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

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -