https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108051
Bug ID: 108051
Summary: Missing array-bounds warning when not using -ftracer
flag
Product: gcc
Version: 12.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: drfiemost at email dot it
Target Milestone: ---
Created attachment 54061
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54061&action=edit
test program
Compiling the attached program, where the key pointer might be unreferenced
when NULL, the warning only shows when using the -ftracer flag. Tested with gcc
version 12.2.0 and 11.3.0.
$ gcc -O2 -Wall -Werror geometry.i
In function ‘HandleOverlayDef’,
inlined from ‘HandleSectionBody’ at geometry.c:2789:18,
inlined from ‘HandleSectionDef’ at geometry.c:2829:10,
inlined from ‘HandleGeometryFile’ at geometry.c:2875:18:
geometry.c:2580:9: error: ‘strncpy’ output may be truncated copying 4 bytes
from a string of length 4 [-Werror=stringop-truncation]
2580 | }
geometry.c:2581:9: error: ‘strncpy’ output may be truncated copying 4 bytes
from a string of length 4 [-Werror=stringop-truncation]
2581 | return False;
cc1: all warnings being treated as errors
$ gcc -O2 -ftracer -Wall -Werror geometry.i
In function ‘HandleOverlayDef’,
inlined from ‘HandleSectionBody’ at geometry.c:2789:18,
inlined from ‘HandleSectionDef’ at geometry.c:2829:10,
inlined from ‘HandleGeometryFile’ at geometry.c:2875:18:
geometry.c:2580:9: error: ‘strncpy’ output may be truncated copying 4 bytes
from a string of length 4 [-Werror=stringop-truncation]
2580 | }
geometry.c:2581:9: error: ‘strncpy’ output may be truncated copying 4 bytes
from a string of length 4 [-Werror=stringop-truncation]
2581 | return False;
geometry.c:2580:9: error: ‘strncpy’ offset [0, 3] is out of the bounds [0, 0]
[-Werror=array-bounds]
2580 | }
geometry.c:2581:9: error: ‘strncpy’ offset [0, 3] is out of the bounds [0, 0]
[-Werror=array-bounds]
2581 | return False;
cc1: all warnings being treated as errors
As a side note the warning message is also a bit cryptic, as the out of bound
would happen only in case the pointer is NULL and not in normal conditions, but
sure is better than no message at all.
See https://gitlab.freedesktop.org/xorg/app/xkbcomp/-/issues/21 for reference.