[Bug stdio/12701] scanf accepts non-matching input
macro at orcam dot me.uk
sourceware-bugzilla@sourceware.org
Tue Dec 3 12:26:34 GMT 2024
https://sourceware.org/bugzilla/show_bug.cgi?id=12701
Maciej W. Rozycki <macro at orcam dot me.uk> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |macro at orcam dot me.uk
--- Comment #30 from Maciej W. Rozycki <macro at orcam dot me.uk> ---
(In reply to Rich Felker from comment #0)
> sscanf("abc", "%4c", buf) returns 1 instead of 0 or EOF (not sure which is
> correct) and leaves no way for the caller to know buf[3] is unfilled.
FYI the way to determine that for "%c" is via "%n", e.g.:
int count;
sscanf("abc", "%4c%n", buf, &count);
and you'll get 3 in "count" as expected, so you know buf[3] has been left
untouched. Though I also read the standard as requiring this case to be
a matching failure.
--
You are receiving this mail because:
You are on the CC list for the bug.
More information about the Glibc-bugs
mailing list