https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102346
Bug ID: 102346 Summary: Missing warning for array bounds Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: fredrik.hederstie...@securitas-direct.com Target Milestone: --- Created attachment 51467 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51467&action=edit example test file There is no warning for array bounds overrun with this code. Compiled with Gcc-11.2.0 gcc -o test string_array_concat.c -W -Wall -Wextra -Warray-bounds=2 -O2 Gives other warning from printf usage only In file included from /usr/include/stdio.h:867, from string_array_concat.c:1: In function ‘printf’, inlined from ‘main’ at string_array_concat.c:13:3: /usr/include/x86_64-linux-gnu/bits/stdio2.h:107:10: warning: ‘%s’ directive argument is null [-Wformat-overflow=] 107 | return __printf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ()); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Though eg CLANG does give warning for this: fredrik@deadbolt ~/test$ clang -o test string_array_concat.c string_array_concat.c:13:30: warning: array index 1 is past the end of the array (which contains 1 element) [-Warray-bounds] printf("item_at_1 = %s\n", item[1]); ^ ~ string_array_concat.c:3:1: note: array 'item' declared here static const char *item[1] = { "TestString" }; ^ string_array_concat.c:15:10: warning: array index 1 is past the end of the array (which contains 1 element) [-Warray-bounds] return item[1]; ^ ~ string_array_concat.c:3:1: note: array 'item' declared here static const char *item[1] = { "TestString" }; ^ 2 warnings generated.