This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: vfprintf typing problem
- From: Roland McGrath <roland at hack dot frob dot com>
- To: David Miller <davem at davemloft dot net>
- Cc: libc-alpha at sourceware dot org
- Date: Wed, 28 Mar 2012 15:25:24 -0700 (PDT)
- Subject: Re: vfprintf typing problem
- References: <20120328.180010.1231759572763962530.davem@davemloft.net>
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