https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117179
Sam James <sjames at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gitlab.com/gnuwget/
| |wget/-/merge_requests/41
--- Comment #3 from Sam James <sjames at gcc dot gnu.org> ---
It is a real bug. Sent a patch:
https://gitlab.com/gnuwget/wget/-/merge_requests/41.
Copying my commit message:
```
init: fix -Warray-bounds in setval_internal_tilde
>= GCC 12 reports an instance of -Warray-bounds in setval_internal_tilde
with the default -DNDEBUG:
```
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[] = {
| ^~~~~~~~
```
setval_internal_tilde calls setval_internal and stores the result in ret;
setval_internal *does* check for if comind is out-of-bounds, but we only
check that *after* dereferencing commands[comind]. Swap the order in the
if() to fix that so we only dereference if we know it's safe.
ChangeLog:
* src/init.c (setval_internal_tilde): Check 'ret' earlier.
```
TL;DR: The issue is that the order in the `if` is wrong.