[Bug middle-end/96406] erroneous -Wstringop-overflow storing into a multidimensional char array
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Jul 31 23:20:27 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96406
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2020-07-31
Component|c |middle-end
Keywords| |diagnostic
CC| |msebor at gcc dot gnu.org
Ever confirmed|0 |1
Summary|erroneous stringop-overflow |erroneous
|warnin |-Wstringop-overflow storing
| |into a multidimensional
| |char array
Status|UNCONFIRMED |WAITING
--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
I can reproduce the warning with the top of the GCC 10 branch (with the
attached translation unit as well as with the small test case below reduced
from it) but no longer with trunk, at least not on my machine or on
https://gcc.godbolt.org. I suspect it got fixed by
g:a2c2cee92e5defff9bf23d3b1184ee96e57e5fdd. The fix is somewhat intrusive so
I'm not 100% comfortable backporting it to GCC 10, but it's been on trunk for a
while so it might be safe by now.
If the warning is still reproducible on trunk it might be a duplicate of
pr96384 which also involves a multidimensional array. Can you retest with the
latest GCC?
$ cat pr96406.c && gcc -O2 -S -Wall -m32 pr96406.c
typedef struct console_info
{
char console_dev[3][32];
int console_owner;
} console_info_t;
static console_info_t console_state = {
.console_dev[1 -1] = { "/dev/ttyS1" },
.console_dev[2 -1] = { "/dev/ttyS1" },
.console_owner = 0
};
void console_param(int type, char *param, int len)
{
char *assign = __builtin_memchr(param, '=', len);
if(assign){
int dev_length = len-(&assign[1]-param);
if((dev_length+1) < 32){
__builtin_memcpy(console_state.console_dev[(type-1)], &assign[1],
dev_length);
console_state.console_dev[(type-1)][dev_length] = '\0';
}
}
}
pr96406.c: In function ‘console_param’:
pr96406.c:22:52: warning: writing 1 byte into a region of size 0
[-Wstringop-overflow=]
22 | console_state.console_dev[(type-1)][dev_length] = '\0';
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
pr96406.c:4:7: note: at offset 0 to object ‘console_dev’ with size 96 declared
here
4 | char console_dev[3][32];
| ^~~~~~~~~~~
More information about the Gcc-bugs
mailing list