|
|
Log in / Subscribe / Register

Would you like signs with those chars?

Would you like signs with those chars?

Posted Oct 26, 2022 8:29 UTC (Wed) by geert (subscriber, #98403)
In reply to: Would you like signs with those chars? by wtarreau
Parent article: Would you like signs with those chars?

BTW, getchar() returns int, not (signed) char, so assigning to char causes truncation.


to post comments

Would you like signs with those chars?

Posted Oct 26, 2022 13:15 UTC (Wed) by wtarreau (subscriber, #51152) [Link] (2 responses)

Yes exactly! But when you're young you don't notice ;-) It's just that 0xFF also ends up the stream. Nowadays it's still possible to seldom spot programs which stop parsing input after 0xFF, and when I see that it just reminds me that they made the same mistake I made, believing that getchar() would return ... a char!

Would you like signs with those chars?

Posted Oct 27, 2022 15:10 UTC (Thu) by cesarb (subscriber, #6266) [Link] (1 responses)

> Nowadays it's still possible to seldom spot programs which stop parsing input after 0xFF

As luck would have it, 0xFF never appears in any valid UTF-8 stream (even in the original definition of UTF-8 which allowed for longer sequences), so the strong push to use UTF-8 everywhere lessens the impact of these bugs.

Would you like signs with those chars?

Posted Oct 27, 2022 17:45 UTC (Thu) by wtarreau (subscriber, #51152) [Link]

No it makes them harder to test in fact. FWIW it was sound processing so any char is valid. And when you do that with unsigned values, you only face the problem when reaching saturation ;-)


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds