<div class="gmail_quote">On Tue, Jun 12, 2012 at 11:14 PM, James Dennett <span dir="ltr"><<a href="mailto:jdennett@google.com" target="_blank">jdennett@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Tue, Jun 12, 2012 at 11:00 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:<br>
> LGTM<br>
><br>
> +      if (Char <= 0xff && isprint(Char))<br>
> +        OS << (char)Char;<br>
><br>
> I appreciate this is just copy-pasted, but I noticed that the 'Char <= 0xff'<br>
> condition is always true here (and the 'else' case can't cope with cases<br>
> where Char > 0xff either). Maybe remove the 'Char <= 0xff' test?<br>
<br>
</div>The range check before calling isprint is a good thing.<br>
<br>
If that's the standard isprint, it's undefined behavior to call it<br>
unless the argument has a value that either is EOF or fits into<br>
unsigned char.  Depending on the library implementation, isprint could<br>
realistically return bogus values for larger values, or could<br>
conceivably segfault.<br></blockquote><div><br></div><div>Sure, but this code is unreachable in the case where Char > 0xff. The 'else' branch also doesn't work for Char > 0xff. The presence of the test is simply misleading; it should either be an assert or should be removed.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'd sooner see a test against UCHAR_MAX than 0xff, but more as<br>
documentation than for correctness -- I don't expect Clang to run on a<br>
machine where CHAR_BIT != 8 (but I've been wrong before).<br></blockquote></div><div><br></div>Yes, if we keep the test as an assert, switching to UCHAR_MAX could make the intent clearer. UCHAR_MAX is guaranteed to be at least 0xff, so there's no correctness issue.