c - Does gcc compiler have any option to recognize memory corruption at compile time? -
#include <stdio.h> #include <string.h> int main() { char arrdst[5] = {0}; char arrsrc[10] = "123456"; memcpy( arrdst, arrsrc, sizeof( arrsrc ) ); return 0; } here in program clear there memory corruption.
is there option in gcc compiler can recognize problem @ compile time?
note: used valgrind --leak-check=full, doesn't help.
$ gcc -wall -o1 t.c in file included /usr/include/string.h:642:0, t.c:3: in function ‘memcpy’, inlined ‘main’ @ t.c:13:9: /usr/include/bits/string3.h:52:3: warning: call __builtin___memcpy_chk overflow destination buffer [enabled default] gcc can recognize some of these. requires turning on optimizations (at least -01) , warnings (-wall, add -wextra too).
Comments
Post a Comment