https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80638
Bug ID: 80638 Summary: -ansi suppresses -Wstringop-overflow for mempcpy Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- A program containing a buffer overflow in a call to mempcpy compiled with the -ansi option GCC is not diagnosed. The same program is diagnosed without the option, or when the call to mempcpy is replaced with memcpy. Calls to known library functions that overflow should be diagnosed regardless of -ansi. $ (set -x && cat a.c && for opt in '' -ansi; do gcc -O2 -S -Wall $opt a.c; done) + cat a.c extern void* mempcpy (void*, const void*, __SIZE_TYPE__); char d[3]; void f (void) { mempcpy (d, "1234", 5); } + for opt in ''\'''\''' -ansi + gcc -O2 -S -Wall a.c a.c: In function ‘f’: a.c:7:3: warning: ‘mempcpy’ writing 5 bytes into a region of size 3 overflows the destination [-Wstringop-overflow=] mempcpy (d, "1234", 5); ^~~~~~~~~~~~~~~~~~~~~~ + for opt in ''\'''\''' -ansi + gcc -O2 -S -Wall -ansi a.c $