<html>
<head>
<base href="https://bugs.webkit.org/" />
</head>
<body>
<p>
<div>
<b><a class="bz_bug_link
bz_status_NEW "
title="NEW - Errors in read() are not handled in WTF::cryptographicallyRandomValuesFromOS."
href="https://bugs.webkit.org/show_bug.cgi?id=146473#c12">Comment # 12</a>
on <a class="bz_bug_link
bz_status_NEW "
title="NEW - Errors in read() are not handled in WTF::cryptographicallyRandomValuesFromOS."
href="https://bugs.webkit.org/show_bug.cgi?id=146473">bug 146473</a>
from <span class="vcard"><a class="email" href="mailto:keith_miller@apple.com" title="Keith Miller <keith_miller@apple.com>"> <span class="fn">Keith Miller</span></a>
</span></b>
<pre>Comment on <span class=""><a href="attachment.cgi?id=255869&action=diff" name="attach_255869" title="Patch">attachment 255869</a> <a href="attachment.cgi?id=255869&action=edit" title="Patch">[details]</a></span>
Patch
View in context: <a href="https://bugs.webkit.org/attachment.cgi?id=255869&action=review">https://bugs.webkit.org/attachment.cgi?id=255869&action=review</a>
<span class="quote">>> Source/WTF/wtf/OSRandomSource.cpp:67
>> + if (currentRead < 0 && !(errno == EAGAIN || errno == EINTR))
>
> I think it would be nicer to check for -1 explicitly, rather than implicitly by including all negatives in the test. The documentation states that read will return -1, 0, or a positive number, and it is nice to be precise.
>
> You can simplify the logic here a bit and avoid testing currentRead twice like so:
>
> if (currentRead == -1) {
> if (!(errno == EAGAIN || errno == EINTR))
> crashUnableToReadFromURandom();
> } else
> amountRead += currentRead;
>
> This helps to clearly separate the failure case from the success case.</span >
That makes sense. Do you think the code you wrote is clearer than:
if (currentRead >= 0)
amountRead += currentRead;
else if (!(errno == EAGAIN || errno == EINTR))
crashUnableToReadFromURandom();
I guess it depends on whether or not you think about the success or failure case first. It also, doesn't make the -1 condition explicit.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are the assignee for the bug.</li>
</ul>
</body>
</html>