On 3/13/19 8:17 PM, Martin Sebor wrote:
> PR 89688 points out a bogus warning about an unterminated
> character array argument to strlen.  The root cause is
> an oversight in the transformation of braced initializer lists
> to STRING_CSTs where the solution implemented last summer only
> considers one-dimensional arrays and skips more complex aggregates
> such as multi-dimensional arrays or structs.
> 
> The folder (string_constant), on the other hand, assumes that
> every a constant character array with an initializer is either
> a properly nul-terminated string (i.e., STRING_CST), or
> an unterminated array or a single character.  If the latter
> then unless the character value is zero it indicates to its
> caller that the constant is not a string.  As a result, we
> end up with a warning.
> 
> To avoid the false positives the attached patch extends
> the solution to those other kinds of aggregates.
> 
> Martin
> 
> gcc-89688.diff
> 
> PR tree-optimization/89688 - -Wstringop-overflow confused by const 2D array 
> of char
> 
> gcc/c/ChangeLog:
> 
>       PR tree-optimization/89688
>       * c-decl.c (finish_decl): Call braced_lists_to_string for more
>       kinds of initializers.
> 
> gcc/c-family/ChangeLog:
> 
>       PR tree-optimization/89688
>       * c-common.c (braced_list_to_string): Make static.
>       (braced_lists_to_strings): Define new function.
>       * c-common.h (braced_list_to_string): Remove.
>       (braced_lists_to_strings): Declare.
> 
> gcc/cp/ChangeLog:
> 
>       PR tree-optimization/89688
>       * typeck2.c (store_init_value): Call braced_lists_to_string for more
>       kinds of initializers.
> 
> gcc/testsuite/ChangeLog:
> 
>       PR tree-optimization/89688
>       * gcc.dg/strlenopt-61.c: New test.
>       * g++.dg/warn/Wstringop-overflow-2.C: New test.
OK.
jeff
> 

Reply via email to