[Bug middle-end/93665] New: missing warning on strncmp reading past unterminated array
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Feb 10 23:08:00 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93665
Bug ID: 93665
Summary: missing warning on strncmp reading past unterminated
array
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
GCC 10 diagnoses the call to strcmp below because it attempts to read past the
end of the unterminated array a3 but not the call to strncmp even though it has
the same bug.
$ cat z.c && gcc -O2 -S -Wall -Wextra -Wpedantic z.c
const char a3[] = { 'a', 'b', 'c' };
const char s4[] = "abcd";
int f (void)
{
return __builtin_strcmp (a3, s4); // warning (good)
}
int g (void)
{
return __builtin_strncmp (a3, s4, sizeof s4); // missing warning
}
z.c: In function ‘f’:
z.c:6:10: warning: ‘__builtin_strcmp’ argument missing terminating nul
[-Wstringop-overflow=]
6 | return __builtin_strcmp (a3, s4); // warning (good)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
z.c:1:12: note: referenced argument declared here
1 | const char a3[] = { 'a', 'b', 'c' };
| ^~
More information about the Gcc-bugs
mailing list