vfprintf typing problem

Roland McGrath roland@hack.frob.com
Wed Mar 28 22:26:00 GMT 2012


The specification for printf is that width parameters have type 'int' when
they are passed in for "%*d" and the like.  So it's clearly proper to use
that in va_arg, and makes sense to use it for storage.  In that context,
negative values have a meaning, so INT_MAX is the true maximum.  Hence I
think it makes sense to diagnose literals in the format string as invalid
when above INT_MAX, and do so early.  We have an early check there already.
But it's checking for (size_t) -1 / sizeof (CHAR_T) - 32, which is far
above INT_MAX even for 32-bit size_t (though not so in w*printf where
CHAR_T is wchar_t).  Would there be a problem with just making that check
also refuse anything above INT_MAX?

In the C standard (C99 and C11), I don't see anything that says anything
one way or another about the valid range of field width specifiers when
they appear directly in the format string.


Thanks,
Roland



More information about the Libc-alpha mailing list