Je fais quelques tests rapides pour mon projet (le but est de savoir si 2 mots sont des anagrammes) : en utilisant valgrind : j'ai cette erreur :
==8423== Memcheck, a memory error detector
==8423== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==8423== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==8423== Command: ./test
==8423==
PARTIE 1
string_are_anagrams :
Censé afficher : 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0
i = 1
i = 2
i = 3
i = 1
i = 2
i = 3
i = 1
i = 2
i = 3
i = 1
i = 2
i = 3
i = 1
i = 2
i = 3
==8423== Invalid read of size 1
==8423== at 0x1091DE: str_length.part.0 (stringslib.c:13)
==8423== by 0x10A100: str_remove_char_with_const_char (anagrammes.c:21)
==8423== by 0x10A306: string_are_anagrams (anagrammes.c:110)
==8423== by 0x108A96: test_part1 (test.c:21)
==8423== by 0x10893A: main (test.c:279)
==8423== Address 0x522d483 is 0 bytes after a block of size 3 alloc'd
==8423== at 0x4C31B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8423== by 0x109B4A: str_duplicate (stringslib.c:284)
==8423== by 0x10A2E7: string_are_anagrams (anagrammes.c:102)
==8423== by 0x108A96: test_part1 (test.c:21)
==8423== by 0x10893A: main (test.c:279)
==8423==
==8423== Invalid read of size 1
==8423== at 0x10A126: str_remove_char_with_const_char (anagrammes.c:27)
==8423== by 0x10A306: string_are_anagrams (anagrammes.c:110)
==8423== by 0x108A96: test_part1 (test.c:21)
==8423== by 0x10893A: main (test.c:279)
==8423== Address 0x522d483 is 0 bytes after a block of size 3 alloc'd
==8423== at 0x4C31B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8423== by 0x109B4A: str_duplicate (stringslib.c:284)
==8423== by 0x10A2E7: string_are_anagrams (anagrammes.c:102)
==8423== by 0x108A96: test_part1 (test.c:21)
==8423== by 0x10893A: main (test.c:279)
==8423==
a = 3
i = 1
i = 2
a = 2
i = 1
a = 1
1
==8423==
==8423== HEAP SUMMARY:
==8423== in use at exit: 0 bytes in 0 blocks
==8423== total heap usage: 2 allocs, 2 frees, 1,027 bytes allocated
==8423==
==8423== All heap blocks were freed -- no leaks are possible
==8423==
==8423== For counts of detected and suppressed errors, rerun with: -v
==8423== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
Je test toutes ces fonctions avec une seule ligne :
printf("%d\n",string_are_anagrams("abc","abc"));
Je ne comprends pas pourquoi Valgrind m'affiche ces erreurs quelqu'un aurait une idée ? Si je ne pouvais pas lire toute la chaine de const char * il me l'aurait dit dans le compilateur non ?
- Edité par RomainGENDREAU1 30 octobre 2019 à 18:12:04
valgrind invalid read
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.