[PATCH 01/15] stdio-common: Don't read real input beyond the field width in scanf [BZ #13988]
Maciej W. Rozycki
macro@redhat.com
Mon Apr 28 13:25:55 GMT 2025
On Fri, 25 Apr 2025, Joseph Myers 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>).
Right, thanks, cf. 3.7.1 as at C23, but it makes me wonder why footnote
349 is needed then that just reinstates what 3.7.1 says. And indeed it
seems wrong to me that say with '%<w>lc' and 'fscanf' <w> counts in terms
of multibyte characters rather than bytes, contrary to said footnote.
Thoughts?
Maciej
More information about the Libc-alpha
mailing list