[PATCH 01/15] stdio-common: Don't read real input beyond the field width in scanf [BZ #13988]

Joseph Myers josmyers@redhat.com
Fri Apr 25 15:47:00 GMT 2025


On Sat, 19 Apr 2025, Maciej W. Rozycki wrote:

> 1. My understanding of ISO C is that the field width limit is given in
>    terms of (possibly multibyte) characters rather than bytes ("[...] that 
>    specifies the maximum field width (in characters)") for all the 
>    conversions except for %c, %s, %[ for which the field width limit is 
>    given in bytes ("the extent of the input field is determined on a 
>    byte-by-byte basis").  Our code seems to implement it the other way 
>    round though.
> 
>    Have I got my understanding backwards?  Am I missing something here?

"character" means "byte" in ISO C unless explicitly preceded by a 
qualification such as "multibyte".  So width is given in bytes (for narrow 
scanf functions as opposed to those in <wchar.h>).

-- 
Joseph S. Myers
josmyers@redhat.com



More information about the Libc-alpha mailing list