<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&#64;apple.com" title="Keith Miller &lt;keith_miller&#64;apple.com&gt;"> <span class="fn">Keith Miller</span></a>
</span></b>
        <pre>Comment on <span class=""><a href="attachment.cgi?id=255869&amp;action=diff" name="attach_255869" title="Patch">attachment 255869</a> <a href="attachment.cgi?id=255869&amp;action=edit" title="Patch">[details]</a></span>
Patch

View in context: <a href="https://bugs.webkit.org/attachment.cgi?id=255869&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=255869&amp;action=review</a>

<span class="quote">&gt;&gt; Source/WTF/wtf/OSRandomSource.cpp:67
&gt;&gt; +        if (currentRead &lt; 0 &amp;&amp; !(errno == EAGAIN || errno == EINTR))
&gt; 
&gt; 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.
&gt; 
&gt; You can simplify the logic here a bit and avoid testing currentRead twice like so:
&gt; 
&gt; if (currentRead == -1) {
&gt;     if (!(errno == EAGAIN || errno == EINTR))
&gt;         crashUnableToReadFromURandom();
&gt; } else
&gt;     amountRead += currentRead;
&gt; 
&gt; 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 &gt;= 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>