|
Par
Tados
Mise à jour : 11/05/2011
188 visites depuis 7 jours,
classé 432/786
|

1 2 3 4 5 6 7 | #include<stdio.h> int main(void) { printf("Hello, world !\n"); return 0; } |
Et bien oui, mais le but ici n'est pas de faire compliqué.gcc -o test0 test0.c |
valgrind ./test0 |
==9029== Memcheck, a memory error detector ==9029== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==9029== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info ==9029== Command: ./test ==9029== Hello, world ! ==9029== ==9029== HEAP SUMMARY: ==9029== in use at exit: 0 bytes in 0 blocks ==9029== total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==9029== ==9029== All heap blocks were freed -- no leaks are possible ==9029== ==9029== For counts of detected and suppressed errors, rerun with: -v ==9029== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 12 from 7) |

==9029== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 12 from 7) |

==9029== HEAP SUMMARY: ==9029== in use at exit: 0 bytes in 0 blocks ==9029== total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==9029== ==9029== All heap blocks were freed -- no leaks are possible |
==9029== in use at exit: 0 bytes in 0 blocks |

==9029== total heap usage: 0 allocs, 0 frees, 0 bytes allocated |

1 2 3 4 5 6 7 8 | #include<stdlib.h> int main(void) { int *p = NULL; *p = 0; return 0; } |
gcc -o test02 test02.c |
tados@tados-laptop:valgrind_tests$ ./test02 Erreur de segmentation |
Ça plante et on n'est pas avancé.tados@tados-laptop:valgrind_tests$ valgrind ./test02 ==9239== Memcheck, a memory error detector ==9239== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==9239== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info ==9239== Command: ./test02 ==9239== ==9239== Invalid write of size 4 ==9239== at 0x80483F9: main (in /home/tados/Documents/SdZ/valgrind_tests/test02) ==9239== Address 0x0 is not stack'd, malloc'd or (recently) free'd ==9239== ==9239== ==9239== Process terminating with default action of signal 11 (SIGSEGV) ==9239== Access not within mapped region at address 0x0 ==9239== at 0x80483F9: main (in /home/tados/Documents/SdZ/valgrind_tests/test02) ==9239== If you believe this happened as a result of a stack ==9239== overflow in your program's main thread (unlikely but ==9239== possible), you can try to increase the size of the ==9239== main thread stack using the --main-stacksize= flag. ==9239== The main thread stack size used in this run was 8388608. ==9239== ==9239== HEAP SUMMARY: ==9239== in use at exit: 0 bytes in 0 blocks ==9239== total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==9239== ==9239== All heap blocks were freed -- no leaks are possible ==9239== ==9239== For counts of detected and suppressed errors, rerun with: -v ==9239== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 12 from 7) Erreur de segmentation |
==9239== Invalid write of size 4 ==9239== at 0x80483F9: main (in /home/tados/Documents/SdZ/valgrind_tests/test02) ==9239== Address 0x0 is not stack'd, malloc'd or (recently) free'd |
tados@tados-laptop:valgrind_tests$ gcc -o test02 test02.c -g tados@tados-laptop:valgrind_tests$ valgrind ./test02 ==9283== Memcheck, a memory error detector ==9283== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==9283== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info ==9283== Command: ./test02 ==9283== ==9283== Invalid write of size 4 ==9283== at 0x80483F9: main (test02.c:6) ==9283== Address 0x0 is not stack'd, malloc'd or (recently) free'd ==9283== ==9283== ==9283== Process terminating with default action of signal 11 (SIGSEGV) ==9283== Access not within mapped region at address 0x0 ==9283== at 0x80483F9: main (test02.c:6) ==9283== If you believe this happened as a result of a stack ==9283== overflow in your program's main thread (unlikely but ==9283== possible), you can try to increase the size of the ==9283== main thread stack using the --main-stacksize= flag. ==9283== The main thread stack size used in this run was 8388608. ==9283== ==9283== HEAP SUMMARY: ==9283== in use at exit: 0 bytes in 0 blocks ==9283== total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==9283== ==9283== All heap blocks were freed -- no leaks are possible ==9283== ==9283== For counts of detected and suppressed errors, rerun with: -v ==9283== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 12 from 7) Erreur de segmentation |
==9283== Invalid write of size 4 ==9283== at 0x80483F9: main (test02.c:6) ==9283== Address 0x0 is not stack'd, malloc'd or (recently) free'd |
1 2 3 4 5 6 7 8 | #include<stdlib.h> int main(void) { int *p = NULL; *p = 0; return 0; } |


1 2 3 4 5 6 7 8 9 | #include<stdlib.h> int main(void) { int i; int *p = NULL; i = *p; return 0; } |
tados@tados-laptop:valgrind_tests$ gcc -o test03 test03.c -g tados@tados-laptop:valgrind_tests$ valgrind ./test03 ==9459== Memcheck, a memory error detector ==9459== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==9459== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info ==9459== Command: ./test03 ==9459== ==9459== Invalid read of size 4 ==9459== at 0x80483CE: main (test03.c:7) ==9459== Address 0x0 is not stack'd, malloc'd or (recently) free'd ==9459== ==9459== ==9459== Process terminating with default action of signal 11 (SIGSEGV) ==9459== Access not within mapped region at address 0x0 ==9459== at 0x80483CE: main (test03.c:7) ==9459== If you believe this happened as a result of a stack ==9459== overflow in your program's main thread (unlikely but ==9459== possible), you can try to increase the size of the ==9459== main thread stack using the --main-stacksize= flag. ==9459== The main thread stack size used in this run was 8388608. ==9459== ==9459== HEAP SUMMARY: ==9459== in use at exit: 0 bytes in 0 blocks ==9459== total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==9459== ==9459== All heap blocks were freed -- no leaks are possible ==9459== ==9459== For counts of detected and suppressed errors, rerun with: -v ==9459== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 12 from 7) Erreur de segmentation |
==9459== Invalid read of size 4 ==9459== at 0x80483CE: main (test03.c:7) ==9459== Address 0x0 is not stack'd, malloc'd or (recently) free'd |



1 2 3 4 5 6 7 8 9 10 11 12 | #include<stdlib.h> int main(void) { int *p = malloc(3 * sizeof *p); if (p != NULL) { p[3] = 0; free(p); } return 0; } |
tados@tados-laptop:valgrind_tests$ gcc -o test04 test04.c -g tados@tados-laptop:valgrind_tests$ valgrind ./test04 ==12044== Memcheck, a memory error detector ==12044== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==12044== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info ==12044== Command: ./test04 ==12044== ==12044== Invalid write of size 4 ==12044== at 0x804843B: main (test04.c:8) ==12044== Address 0x4185034 is 0 bytes after a block of size 12 alloc'd ==12044== at 0x4023C1C: malloc (vg_replace_malloc.c:195) ==12044== by 0x8048428: main (test04.c:5) ==12044== ==12044== ==12044== HEAP SUMMARY: ==12044== in use at exit: 0 bytes in 0 blocks ==12044== total heap usage: 1 allocs, 1 frees, 12 bytes allocated ==12044== ==12044== All heap blocks were freed -- no leaks are possible ==12044== ==12044== For counts of detected and suppressed errors, rerun with: -v ==12044== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 12 from 7) |
1 2 3 4 5 6 7 8 9 10 11 12 | #include<stdlib.h> int main(void) { int *p = malloc(3 * sizeof *p); if (p != NULL) { p[-1] = 0; free(p); } return 0; } |
tados@tados-laptop:valgrind_tests$ gcc -o test05 test05.c -g tados@tados-laptop:valgrind_tests$ valgrind ./test05 ==12073== Memcheck, a memory error detector ==12073== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==12073== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info ==12073== Command: ./test05 ==12073== ==12073== Invalid write of size 4 ==12073== at 0x804843B: main (test05.c:8) ==12073== Address 0x4185024 is 4 bytes before a block of size 12 alloc'd ==12073== at 0x4023C1C: malloc (vg_replace_malloc.c:195) ==12073== by 0x8048428: main (test05.c:5) ==12073== ==12073== ==12073== HEAP SUMMARY: ==12073== in use at exit: 0 bytes in 0 blocks ==12073== total heap usage: 1 allocs, 1 frees, 12 bytes allocated ==12073== ==12073== All heap blocks were freed -- no leaks are possible ==12073== ==12073== For counts of detected and suppressed errors, rerun with: -v ==12073== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 12 from 7) |

1 2 3 4 5 6 7 8 9 10 11 12 | #include<stdlib.h> int main(void) { int *p = malloc(sizeof *p); if (p != NULL) { free(p); *p = 1; } return 0; } |
tados@tados-laptop:valgrind_tests$ gcc -o test06 test06.c -g tados@tados-laptop:valgrind_tests$ valgrind ./test06 ==11890== Memcheck, a memory error detector ==11890== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==11890== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info ==11890== Command: ./test06 ==11890== ==11890== Invalid write of size 4 ==11890== at 0x8048444: main (test06.c:9) ==11890== Address 0x4185028 is 0 bytes inside a block of size 4 free'd ==11890== at 0x4023836: free (vg_replace_malloc.c:325) ==11890== by 0x804843F: main (test06.c:8) ==11890== ==11890== ==11890== HEAP SUMMARY: ==11890== in use at exit: 0 bytes in 0 blocks ==11890== total heap usage: 1 allocs, 1 frees, 4 bytes allocated ==11890== ==11890== All heap blocks were freed -- no leaks are possible ==11890== ==11890== For counts of detected and suppressed errors, rerun with: -v ==11890== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 12 from 7) |

1 2 3 4 5 6 7 8 9 10 11 | #include<stdlib.h> int main(void) { int *p = malloc(sizeof *p); if (p != NULL) free(p); p = malloc(sizeof *p); p = NULL; return 0; } |
tados@tados-laptop:valgrind_tests$ gcc -o test07 test07.c -g tados@tados-laptop:valgrind_tests$ valgrind ./test07 ==9565== Memcheck, a memory error detector ==9565== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==9565== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info ==9565== Command: ./test07 ==9565== ==9565== ==9565== HEAP SUMMARY: ==9565== in use at exit: 4 bytes in 1 blocks ==9565== total heap usage: 2 allocs, 1 frees, 8 bytes allocated ==9565== ==9565== LEAK SUMMARY: ==9565== definitely lost: 4 bytes in 1 blocks ==9565== indirectly lost: 0 bytes in 0 blocks ==9565== possibly lost: 0 bytes in 0 blocks ==9565== still reachable: 0 bytes in 0 blocks ==9565== suppressed: 0 bytes in 0 blocks ==9565== Rerun with --leak-check=full to see details of leaked memory ==9565== ==9565== For counts of detected and suppressed errors, rerun with: -v ==9565== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 12 from 7) |
tados@tados-laptop:valgrind_tests$ valgrind --leak-check=full ./test07 ==9630== Memcheck, a memory error detector ==9630== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==9630== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info ==9630== Command: ./test07 ==9630== ==9630== ==9630== HEAP SUMMARY: ==9630== in use at exit: 4 bytes in 1 blocks ==9630== total heap usage: 2 allocs, 1 frees, 8 bytes allocated ==9630== ==9630== 4 bytes in 1 blocks are definitely lost in loss record 1 of 1 ==9630== at 0x4023C1C: malloc (vg_replace_malloc.c:195) ==9630== by 0x804844B: main (test07.c:8) ==9630== ==9630== LEAK SUMMARY: ==9630== definitely lost: 4 bytes in 1 blocks ==9630== indirectly lost: 0 bytes in 0 blocks ==9630== possibly lost: 0 bytes in 0 blocks ==9630== still reachable: 0 bytes in 0 blocks ==9630== suppressed: 0 bytes in 0 blocks ==9630== ==9630== For counts of detected and suppressed errors, rerun with: -v ==9630== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 12 from 7) |
1 2 3 4 5 6 7 8 9 10 11 | #include<stdlib.h> int main(void) { int *p = malloc(sizeof *p); if (p != NULL) free(p); p = malloc(sizeof *p); p = NULL; return 0; } |

1 2 3 4 5 6 7 8 9 10 11 12 13 | #include<stdlib.h> #include<stdio.h> int main(void) { int i; int j; if (j) { printf("Hello, world !\n"); } return 0; } |

tados@tados-laptop:valgrind_tests$ gcc -o test08 test08.c -g tados@tados-laptop:valgrind_tests$ valgrind ./test08 ==10090== Memcheck, a memory error detector ==10090== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==10090== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info ==10090== Command: ./test08 ==10090== ==10090== Conditional jump or move depends on uninitialised value(s) ==10090== at 0x80483F2: main (test05.c:8) ==10090== Hello, world ! ==10090== ==10090== HEAP SUMMARY: ==10090== in use at exit: 0 bytes in 0 blocks ==10090== total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==10090== ==10090== All heap blocks were freed -- no leaks are possible ==10090== ==10090== For counts of detected and suppressed errors, rerun with: -v ==10090== Use --track-origins=yes to see where uninitialised values come from ==10090== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 12 from 7) |
tados@tados-laptop:valgrind_tests$ valgrind --track-origins=yes ./test08 ==10112== Memcheck, a memory error detector ==10112== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==10112== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info ==10112== Command: ./test08 ==10112== ==10112== Conditional jump or move depends on uninitialised value(s) ==10112== at 0x80483F2: main (test08.c:8) ==10112== Uninitialised value was created by a stack allocation ==10112== at 0x80483EA: main (test08.c:5) ==10112== Hello, world ! ==10112== ==10112== HEAP SUMMARY: ==10112== in use at exit: 0 bytes in 0 blocks ==10112== total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==10112== ==10112== All heap blocks were freed -- no leaks are possible ==10112== ==10112== For counts of detected and suppressed errors, rerun with: -v ==10112== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 12 from 7) |
1 2 3 4 5 6 7 8 9 10 11 12 13 | #include<stdlib.h> #include<stdio.h> int main(void) { int i; int j; if (j) { printf("Hello, world !\n"); } return 0; } |

1 2 3 4 5 6 7 8 9 10 11 12 | #include<stdlib.h> #include<stdio.h> int main(void) { int *i = malloc(sizeof *i); if (*i) { printf("Hello, world !\n"); } return 0; } |
tados@tados-laptop:valgrind_tests$ gcc -o test09 test09.c -g tados@tados-laptop:valgrind_tests$ valgrind --track-origins=yes ./test06 ==10241== Memcheck, a memory error detector ==10241== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==10241== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info ==10241== Command: ./test09 ==10241== ==10241== Conditional jump or move depends on uninitialised value(s) ==10241== at 0x8048435: main (test09.c:7) ==10241== Uninitialised value was created by a heap allocation ==10241== at 0x4023C1C: malloc (vg_replace_malloc.c:195) ==10241== by 0x8048428: main (test09.c:6) ==10241== ==10241== ==10241== HEAP SUMMARY: ==10241== in use at exit: 4 bytes in 1 blocks ==10241== total heap usage: 1 allocs, 0 frees, 4 bytes allocated ==10241== ==10241== LEAK SUMMARY: ==10241== definitely lost: 4 bytes in 1 blocks ==10241== indirectly lost: 0 bytes in 0 blocks ==10241== possibly lost: 0 bytes in 0 blocks ==10241== still reachable: 0 bytes in 0 blocks ==10241== suppressed: 0 bytes in 0 blocks ==10241== Rerun with --leak-check=full to see details of leaked memory ==10241== ==10241== For counts of detected and suppressed errors, rerun with: -v ==10241== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 12 from 7) |

1 2 3 4 5 6 7 | int myMmax(int a, int b) { if (a > b) return a; else return b; } |

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | int myMax(int a, int b) { if (a > b) return a; else return b; } int myAbs(int a) { return myMax(-a, a); } void foo(int *i) { *i = myAbs(*i); } int main(void) { int i; foo(&i); return 0; } |
tados@tados-laptop:valgrind_tests$ gcc -o test10 test10.c -g tados@tados-laptop:valgrind_tests$ valgrind --track-origins=yes ./test10 ==10630== Memcheck, a memory error detector ==10630== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==10630== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info ==10630== Command: ./test10 ==10630== ==10630== Conditional jump or move depends on uninitialised value(s) ==10630== at 0x80483BD: myMax (test10.c:3) ==10630== by 0x80483E4: myAbs (test10.c:11) ==10630== by 0x80483F7: foo (test10.c:16) ==10630== by 0x8048404: main (test10.c:22) ==10630== Uninitialised value was created by a stack allocation ==10630== at 0x80483EA: main (test10.c:20) ==10630== ==10630== ==10630== HEAP SUMMARY: ==10630== in use at exit: 0 bytes in 0 blocks ==10630== total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==10630== ==10630== All heap blocks were freed -- no leaks are possible ==10630== ==10630== For counts of detected and suppressed errors, rerun with: -v ==10630== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 12 from 7) |

1 2 3 4 5 6 | int main(void) { int array[3]; array[3] = 0; return 0; } |
tados@tados-laptop:valgrind_tests$ gcc -o test11 test11.c -g tados@tados-laptop:valgrind_tests$ valgrind ./test11 ==12532== Memcheck, a memory error detector ==12532== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==12532== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info ==12532== Command: ./test11 ==12532== ==12532== ==12532== HEAP SUMMARY: ==12532== in use at exit: 0 bytes in 0 blocks ==12532== total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==12532== ==12532== All heap blocks were freed -- no leaks are possible ==12532== ==12532== For counts of detected and suppressed errors, rerun with: -v ==12532== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 12 from 7) |
tados@tados-laptop:valgrind_tests$ valgrind --tool=exp-ptrcheck ./test11 ==12579== exp-ptrcheck, a heap, stack & global array overrun detector ==12579== NOTE: This is an Experimental-Class Valgrind Tool ==12579== Copyright (C) 2003-2009, and GNU GPL'd, by OpenWorks Ltd et al. ==12579== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info ==12579== Command: ./test11 ==12579== ==12579== ==12579== For counts of detected and suppressed errors, rerun with: -v ==12579== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) |


|
|
[C++] Déboguer avec Code::Blocks |
|
|
Développez vos jeux-vidéo 3D avec OpenGL 3.1 |
|
|
[C++] Notions avancées |
|
|
[C++] Maîtriser le compilateur g++ |