#include<stdio.h>
#include<stdlib.h>
int main()
int i;
int len = 4;
int *pt = (int*)malloc(len*sizeof(int));
int *p = pt;
for(i=0;i<len;i++)
*p = 5;
return 0;
执行命令:valgrind ./2
==2918== Invalid write of size 4
==2918== at 0x400570: main (2.c:16)
==2918== Address 0x5204050 is 0 bytes after a block of size 16 alloc'd
==2918== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2918== by 0x400545: main (2.c:8)