This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Add a character size parameter to c_strlen/get_range_strlen

On 08/21/2018 02:59 AM, Richard Biener wrote:
On Tue, 21 Aug 2018, Bernd Edlinger wrote:

gcc -S -O2 -Wall -Wformat-overflow -ftrack-macro-expansion=0 -fshort-wchar builtin-sprintf-warn-20.c
builtin-sprintf-warn-20.c: In function 'test':
builtin-sprintf-warn-20.c:19:39: warning: hex escape sequence out of range
19 |     ? (char*)L"\x4142\x4344" : (char*)L"\x41424344\x45464748";
    |                                       ^~~~~~~~~~~~~~~~~~~~~~~

Hmm, this test might create some noise on short-wchar targets.

I would prefer a warning here, about the wrong type of the parameter.
The buffer overflow is only a secondary thing.

For constant objects like those, the GIMPLE type is still guaranteed to be reliable,

TREE_TYPE of tcc_declaration and tcc_constant trees should more-or-less
(minus qualifications not affecting semantics) be those set by

A warning for these cases should be relatively  straightforward
to add to the sprintf pass.  It would require c_strlen() to return
the type of the string argument to the caller.  That way sprintf's
format_string() function could compare the string type to the
expected type of the directive.

If c_strlen() fails because the types don't match as it does now
there's no easy way for format_string() to know what the actual
type of the string is (not without doing the same work c_strlen()
would have done).


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]