On 11/26/18 1:55 PM, Martin Sebor wrote:
> In the committed patch I forgot that the CONSTRUCTOR to STRING_CST
> transformation introduced this summer only takes place for arrays
> of char and not also those of wide characters.  That resulted in
> sprintf incorrectly getting STRING_CSTs for individual elements
> of constant wide character arrays like in the example below, and
> issuing a warning when that element was not nul and was passed
> to %s.
> 
> The test that was supposed top exercise this was incomplete (it
> was testing the %s directive rather than %ls), and so the bug
> sneaked in unnoticed.
> 
> The attached patch restricts the change committed in r266418 to
> only do its thing for non-array variables of wide character types
> or for plain chars.  It also moves the wide string test into a new
> file and corrects the problems there.  Since the the CONSTRUCTOR
> to STRING_CST transformation doesn't take place for wide arrays
> the test fails a bunch of cases.  I have XFAILed those until
> the transformation is implemented.
> 
> I have tested this fix on x86_64-linux with no regression.  Unless
> there are concerns with this I'll commit it in the next day or so
> to unblock the failing Glibc builds.
> 
> Martin
> 
> On 11/26/18 12:27 PM, Martin Sebor wrote:
>> On 11/26/18 10:27 AM, Joseph Myers wrote:
>>> On Fri, 23 Nov 2018, Martin Sebor wrote:
>>>
>>>> I have now committed this patch as r266418.
>>>
>>> This commit introduced spurious warnings that break the glibc testsuite
>>> build.
>>>
>>> bug-ungetwc2.c:62:17: error: '%ls' directive argument is not a
>>> nul-terminated string [-Werror=format-overflow=]
>>>     62 |   fprintf (fp, "%ls", write_wchars);
>>>        |                 ^~~   ~~~~~~~~~~~~
>>> bug-ungetwc2.c:10:15: note: referenced argument declared here
>>>     10 | const wchar_t write_wchars[] = {L'A', 0x00C4, L'B', L'\0'};
>>>        |               ^~~~~~~~~~~~
>>>
>>> Reduced test (compile with -Wall, should not produce any warnings but
>>> does after that commit):
>>>
>>> const __WCHAR_TYPE__ s[] = { L'A', L'\0' };
>>> void f (void) { __builtin_printf ("%ls", s); }
>>
>> Thanks for the test case.  I see the problem and I'm testing a simple
>> fix.
>>
>> Martin
> 
> 
> gcc-wide-nul-fix.diff
> 
> gcc/ChangeLog:
> 
>       * expr.c (string_constant): Handle top-level decls of all character
>       types and subobjects of narrow character type.
> 
> gcc/testsuite/ChangeLog:
> 
>       * gcc.dg/warn-sprintf-no-nul-2.c: Move incomplete tests from here...
>       * gcc.dg/warn-sprintf-no-nul-3.c: ...to here and complete them.
OK.
jeff

Reply via email to