https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117179
Bug ID: 117179
Summary: Confusing -Warray-bounds output for wget
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: sjames at gcc dot gnu.org
CC: qing.zhao at oracle dot com
Target Milestone: ---
Qing - let me know if you would prefer me email these or report differently.
With wget from git (8775506f632f14404e4755dbae679dea07abf12a) and using Qing's
RFC patch (https://gcc.gnu.org/pipermail/gcc-patches/2024-July/657150.html) for
-fdiagnostics-explain-harder, I see:
```
$ gcc -std=gnu23 -DHAVE_CONFIG_H -DSYSTEM_WGETRC=\"/usr/local/etc/wgetrc\"
-DLOCALEDIR=\"/usr/local/share/locale\" -I. -I../lib -I../lib
-I/usr/include/p11-kit-1 -DHAVE_LIBGNUTLS -DNDEBUG -O2 -Werror=array-bounds
-MT init.o -MD -MP -MF $depbase.Tpo -c -o init.o init.c
In function ‘setval_internal_tilde’,
inlined from ‘run_wgetrc’ at init.c:710:16:
init.c:940:17: error: array subscript [0, 167] is outside array bounds of
‘const struct <anonymous>[168]’ [-Werror=array-bounds=]
940 | if (((commands[comind].action == cmd_file) ||
| ~~~~~~~~^~~~~~~~
init.c: In function ‘run_wgetrc’:
init.c:135:3: note: while referencing ‘commands’
135 | } commands[] = {
| ^~~~~~~~
cc1: some warnings being treated as errors
```
With -fdiagnostics-explain-harder, IMO the output doesn't help much:
```
$ gcc -std=gnu23 -DHAVE_CONFIG_H -DSYSTEM_WGETRC=\"/usr/local/etc/wgetrc\"
-DLOCALEDIR=\"/usr/local/share/locale\" -I. -I../lib -I../lib
-I/usr/include/p11-kit-1 -DHAVE_LIBGNUTLS -DNDEBUG -O2 -Werror=array-bounds
-fdiagnostics-explain-harder -MT init.o -MD -MP -MF $depbase.Tpo -c -o init.o
init.c
In function ‘setval_internal_tilde’,
inlined from ‘run_wgetrc’ at init.c:710:16:
init.c:940:17: error: array subscript [0, 167] is outside array bounds of
‘const struct <anonymous>[168]’ [-Werror=array-bounds=]
940 | if (((commands[comind].action == cmd_file) ||
| ~~~~~~~~^~~~~~~~
‘run_wgetrc’: events 1-2
940 | if (((commands[comind].action == cmd_file) ||
| ^ ~~~~~~~~~~~~~~~~
| | |
| | (2) out of array bounds here
| (1) when the condition is evaluated to true
init.c: In function ‘run_wgetrc’:
init.c:135:3: note: while referencing ‘commands’
135 | } commands[] = {
| ^~~~~~~~
cc1: some warnings being treated as errors
```
As a aside, the warning starts with GCC 12, but it might be legitimate, I'm
just filing this for the output issue.