logoalt Hacker News

carlosneves • today at 9:38 AM • 1 reply • view on HN

Was suspecting the same thing. But I think, because C strings are null-terminated, they allow reading up to 1 byte after its end.

In your example, "%" would cause switch ('\0') which would fall in the default case.


Replies

ginko • today at 9:52 AM

Yeah, but that only prints an error and keeps going, so next loop it will read past the null terminator. So I think looperhacks is correct.

The function should probably return on error.