Why does following code not produce a warning with gcc?
#include <string.h>
int main() {
char d[1], s[4] = {0, 1, 2, 3};
memcpy(d, s, 8);
}
The gcc documentation says:
-Wstringop-overflow
-Wstringop-overflow=type
Warn for calls to string manipulation functions such as memcpy and strcpy that are determined to overflow the destination buffer.
...
Option -Wstringop-overflow=2 is enabled by default.
So I would expect a stringop-overflow warning. But no warnings at all.
When trying to run the program it crashes, which makes sense.
gcc -Wall -Wextra -pedantic test.c -o test_app
./test_app
*** stack smashing detected ***: terminated
Aborted
I'm using gcc 11.2, but also tried gcc 9.4. No warning in either case.