rex@monet:/tmp/Debug$ valgrind ./segfault ==8756== Memcheck, a memory error detector ==8756== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al. ==8756== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info ==8756== Command: ./segfault ==8756== ==8756== Use of uninitialised value of size 4 ==8756== at 0x804840A: main (segfault.c:6) ...
$ cat -b debordement.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #define MAX_ALLOC 10
4 int main(void){
5 char *tab=malloc(MAX_ALLOC*sizeof(char));
6 int i;
7 for(i=1;i<=MAX_ALLOC;i++) tab[i]=i;
8 for(i=1;i<=MAX_ALLOC;i++) printf("%d\n",tab[i]);
9 return 0;
10 }
$ valgrind ./debordement
==5345== Memcheck, a memory error detector
...
==5345== Invalid write of size 1
==5345== at 0x804847D: main (debordement.c:7)
==5345== Address 0x41a8032 is 0 bytes after a block of size 10 alloc'd
==5345== at 0x4028308: malloc (vg_replace_malloc.c:263)
==5345== by 0x8048460: main (debordement.c:5)
...