[Bug middle-end/96900] [9/10/11 Regression] bogus -Warray-bounds on strlen with valid pointer obtained from just-past-the-end
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Sep 2 18:57:19 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96900
--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
The underlying cause is fold_nonarray_ctor_reference() returning a scalar zero
for apparently out-of-bounds references when determining the initializer for
s.a from &s.a[sizeof s.a]. Its caller, constant_byte_string(), then interprets
that as an array of single element initialized to zero, but it incorrectly
returns the offset from the beginning of s (i.e., 4 rather than 3 minus 3 for
sizeof s.a). Its caller, c_strlen(), then uses the size of the one-element
initializer (for "") and the offset (positive 1) as the basis for issuing the
warning.
More information about the Gcc-bugs
mailing list