[Bug tree-optimization/96826] New: missing warning appending to the result of strdup
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Aug 27 22:06:29 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96826
Bug ID: 96826
Summary: missing warning appending to the result of strdup
Product: gcc
Version: 11.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: ---
Appending to a string created by strdup is not diagnosed by could be by looking
up the origin of the destination pointer and, if it's used in a call to a
function like strcat, or if it's accessed at an offset derived from strlen of
either the copy or the original (with no subtraction), issuing
-Wstringop-overflow.
$ cat z.c && /build/gcc-master/gcc/xgcc -B /build/gcc-master/gcc -O2 -S -Wall
z.c
void* f0 (const char *s)
{
char *t = __builtin_strdup (s);
__builtin_strcat (t, "xyz"); // missing warning
return t;
}
void* f1 (const char *s)
{
char *t = __builtin_strdup (s);
t += __builtin_strlen (t);
t[0] = 'x';
t[1] = 'y'; // missing warning
t[2] = 'z'; // ditto
return t;
}
void* f2 (const char *s)
{
char *t = __builtin_strdup (s);
t += __builtin_strlen (t);
__builtin_sprintf (t, "%i", 123); // missing warning
return t;
}
More information about the Gcc-bugs
mailing list