[Bug middle-end/93531] New: missing -Wrestrict calling strcat with strcpy as argument
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Jan 31 20:45:00 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93531
Bug ID: 93531
Summary: missing -Wrestrict calling strcat with strcpy as
argument
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: ---
In the following test case only the overlapping calls are diagnosed that pass
the source argument as the destination are diagnosed; none of those is that
pass the result of a string function that returns its argument to another.
$ cat a.c && gcc -O2 -S -Wall a.c
extern void* memcpy (void*, const void*, __SIZE_TYPE__);
extern char* strcat (char*, const char*);
extern char* strcpy (char*, const char*);
const char *s1, *s2;
void f0 (char *s)
{
memcpy (memcpy (s, s, 4), s1, 4); // missing -Wrestrict
}
void f1 (char *s)
{
memcpy (memcpy (s, s1, 4), s, 4); // missing -Wrestrict
}
void g0 (char *s)
{
strcpy (strcpy (s, s), s1); // -Wrestrict (good)
}
void g1 (char *s)
{
strcpy (strcpy (s, s1), s); // missing -Wrestrict
}
void h0 (char *s)
{
strcat (strcat (s, s), s1); // -Wrestrict (good)
}
void h1 (char *s)
{
strcat (strcat (s, s1), s); // missing -Wrestrict
}
a.c: In function ‘g0’:
a.c:20:3: warning: ‘strcpy’ source argument is the same as destination
[-Wrestrict]
20 | strcpy (strcpy (s, s), s1); // -Wrestrict (good)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
a.c: In function ‘h0’:
a.c:31:3: warning: ‘strcat’ source argument is the same as destination
[-Wrestrict]
31 | strcat (strcat (s, s), s1); // -Wrestrict (good)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
More information about the Gcc-bugs
mailing list