[RFC] scanf: add non-allocating bounded string input via %!s / %![...] / %!c (size before pointer)
Joseph Myers
josmyers@redhat.com
Fri Oct 17 15:58:26 GMT 2025
On Fri, 17 Oct 2025, Yair Lenga wrote:
> * No other format decorations are allowed with '!':
> - **no** numeric field width digits,
> - **no** length modifiers (h, hh, l, ll, L, j, z, t),
> - **no** positional "$".
> If present, the conversion is a format error (treated as a match failure).
I'm concerned about the non-orthogonal design being proposed, as well as
the problems for i18n support.
For printf width and precision, "*" can also be given as "*N$" to take the
Nth argument. This is necessary to support %N$ argument reordering for
i18n, since mixing numbered and positional arguments in the same format
string is unsupported.
The same principle should also apply for anything taking a size argument
for scanf: it should be able to have N$ specified so it can be used in
strings with %N$.
The existing "*" for printf takes an int. There's a proposal for C2y
(N3691) to allow a length modifier for precision and add the option of '^'
instead of '*' for unsigned precision (the proposal only deals with
precision, not width). The proposal doesn't deal with "*N$" since that's
a POSIX feature not an ISO C one, but one might reasonably expect to be
able to use "*N$" and "^N$" together with the new support for length
modifiers.
Now, "*" already has an existing incompatible meaning for scanf so can't
be used for a new feature here. But in the other ways the proposed
feature could be more consistent with printf - so supporting a positional
modifier, and defaulting to int with potential support for length
modifiers if such a feature is accepted for printf in C2y in future.
--
Joseph S. Myers
josmyers@redhat.com
More information about the Libc-alpha
mailing list