3 ms·
Another bug: if `maxlen <= 0`, then it will overwrite the character before the start of `ptr`. And then there's the infinite loop if `maxlen > INT_MAX` on 64-bi
by gsliepen 3y ago
Another bug: if `maxlen <= 0`, then it will overwrite the character before the start of `ptr`. And then there's the infinite loop if `maxlen > INT_MAX` on 64-bit machines. And maybe `out + skipped` can wrap as well?
- jcranmer 3y agomaxlen is meant to be a constant provided by a #define, so I wouldn't be worried about things going haywire if maxlen is a weird value. But C-like code in general makes me nervous in parsers, since there's many ways things can go wrong and C is inherently fail-deadly if you make a mistake.
- jstimpfle 3y agoCoding in C doesn't mean that you shouldn't create a layering of appropriate abstractions.
- SubjectToChange 3y agoThe problem is that writing abstractions in C is more difficult than virtually any other practical language.
- jstimpfle 3y agoThat's a wild claim. Why do you think is that? What is an abstraction and what do you need to code it?
- NobodyNada 3y agoOne more: if an error occurs while reading the first character, the function returns -out = 0, which violates the documented behavior that errors are negative, and means a caller can’t distinguish between a failing to read and reading an empty file.