https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82455
Bug ID: 82455 Summary: missing -Warray-bounds on strcpy offset in an out-of-bounds range Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- The -Warray-bounds warning is only issued for (a subset of) instances of cases where the index/offset is constant. The warning could be made more effective by making use of range information to detect non-constant out-of-bounds offsets as well. The test case below shows an instance where the warning is missing. (It also shows an instance of missing -Wstringop-overflow warning but that one is the subject of a separate bug report). $ cat z.c && gcc -O2 -S -Wall -Wextra z.c void fcst (char *d) { char a[2] = "0"; __builtin_strcpy (d, a + 3); // -Warray-bounds (good) // missing -Wstringop-overflow } void frng (char *d, int i) { char a[2] = "0"; if (i < 3) i = 3; __builtin_strcpy (d, a + i); // both warnings missing // (array index out of bounds // and reading past the end) }