Does gcc compiler have any option to recognize memory corruption at compile time?

c, gcc

Solution

$ gcc -Wall -O1 t.c 
In file included from /usr/include/string.h:642:0,
                 from t.c:3:
In function ‘memcpy’,
    inlined from ‘main’ at t.c:13:9:
/usr/include/bits/string3.h:52:3: warning: call to __builtin___memcpy_chk
   will always overflow destination buffer [enabled by default]

GCC can recognize some of these. That generally requires turning on optimizations (at least `-01`) and warnings (`-Wall`, add `-Wextra` too).

Problem

``` #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 this program it is clear that there is a memory corruption. Is there any option in gcc compiler by which I can recognize this problem at compile time? Note: I used `valgrind --leak-check=full`, but it doesn't help.

Original source