Problème avec le serveur d'entrainement

Bonjour,
lorsque je lance mon programme pour l'exercice 4 dans le serveur d'entrainement j'ai cette erreur :
"Arrêt anormal du processus, signal ayant mis fin a son exécution : "Segmentation fault" (11)."
Pourtant j'ai fait pas mal de test chez moi et le programme marche à la perfection ,
j'aimerai bien que quelqu'un puisse m'en expliquer la cause. Merci

J'ai réussi à détecter la source du problème mais je n'en voit pas la raison , dans mon code j'utilise un tableau de vector et l'erreur se produit lorsque j'appelle l'un des éléments d'un des vector de mon tableau.Malgré cela je ne voit toujours pas la raison du dysfonctionnement.

Salut,

http://fr.wikipedia.org/wiki/Erreur_de_segmentation

Tu as essayé d'accéder à une zone mémoire qui ne t'appartenait pas. Si ça marche chez toi et pas sur le serveur d'entraînement, c'est sans doute parce que chez toi un peu plus de mémoire t'es allouée et tu peux facilement y accéder sans segfault. Tu peux utiliser des outils comme valgrind pour déterminer d'où ça peut venir.

Je sais très bien ce qu'est une erreur de segmentation de plus j'ai localiser la ligne précise qui ce trouve être la cause de l'erreur,malgré tout j'ai beau retourné le code dans tous les sens je ne comprend pas mon erreur.

Tu as essayé d'utiliser valgrind, comme je te l'ai suggéré dans mon message précédent ?

==4536== Invalid read of size 4
==4536== at 0x4010BB: Calcul(int, int*, std::vector >, std::vector >, int) (in /home/serialk/prologin/a.out)
==4536== by 0x4011FF: Calcul(int, int*, std::vector >, std::vector >, int) (in /home/serialk/prologin/a.out)
==4536== by 0x400E37: main (in /home/serialk/prologin/a.out)
==4536== Address 0x5a19104 is 0 bytes after a block of size 20 alloc'd
==4536== at 0x4C2AFE7: operator new (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4536== by 0x400C89: main (in /home/serialk/prologin/a.out)
==4536==
==4536== Invalid write of size 4
==4536== at 0x4010E5: Calcul(int, int*, std::vector >, std::vector >, int) (in /home/serialk/prologin/a.out)
==4536== by 0x4011FF: Calcul(int, int*, std::vector >, std::vector >, int) (in /home/serialk/prologin/a.out)
==4536== by 0x400E37: main (in /home/serialk/prologin/a.out)
==4536== Address 0x5a19104 is 0 bytes after a block of size 20 alloc'd
==4536== at 0x4C2AFE7: operator new (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4536== by 0x400C89: main (in /home/serialk/prologin/a.out)
==4536==
==4536== Invalid read of size 4
==4536== at 0x401013: Calcul(int, int*, std::vector >, std::vector >, int) (in /home/serialk/prologin/a.out)
==4536== by 0x4011FF: Calcul(int, int*, std::vector >, std::vector >, int) (in /home/serialk/prologin/a.out)
==4536== by 0x4011FF: Calcul(int, int*, std::vector >, std::vector >, int) (in /home/serialk/prologin/a.out)
==4536== by 0x400E37: main (in /home/serialk/prologin/a.out)
==4536== Address 0x5a19454 is 0 bytes after a block of size 20 alloc'd
==4536== at 0x4C2A879: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4536== by 0x401EBD: __gnu_cxx::new_allocator ::allocate(unsigned long, void const*) (in /home/serialk/prologin/a.out)
==4536== by 0x401CAE: std::_Vector_base >::_M_allocate(unsigned long) (in /home/serialk/prologin/a.out)
==4536== by 0x401A26: std::_Vector_base >::_M_create_storage(unsigned long) (in /home/serialk/prologin/a.out)
==4536== by 0x4015DA: std::_Vector_base >::_Vector_base(unsigned long, std::allocator const&) (in /home/serialk/prologin/a.out)
==4536== by 0x40143A: std::vector >::vector(std::vector > const&) (in /home/serialk/prologin/a.out)
==4536== by 0x4011C7: Calcul(int, int*, std::vector >, std::vector >, int) (in /home/serialk/prologin/a.out)
==4536== by 0x4011FF: Calcul(int, int*, std::vector >, std::vector >, int) (in /home/serialk/prologin/a.out)
==4536== by 0x400E37: main (in /home/serialk/prologin/a.out)
==4536==
==4536== Stack overflow in thread 1: can't grow stack to 0x7fe801ff8
==4536==
==4536== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==4536== Access not within mapped region at address 0x7FE801FF8
==4536== at 0x402320: __gnu_cxx::__normal_iterator > >::base() const (in /home/serialk/prologin/a.out)
==4536== by 0x40223F: std::_Iter_base \<__gnu_cxx::__normal_iterator const="" std::allocator="" std::vector=""> > >, true>::_S_base(__gnu_cxx::__normal_iterator > >) (in /home/serialk/prologin/a.out)
==4536== by 0x4021A0: std::_Niter_base \<__gnu_cxx::__normal_iterator const="" std::allocator="" std::vector=""> > > >::iterator_type std::__niter_base \<__gnu_cxx::__normal_iterator const="" std::allocator="" std::vector=""> > > >(__gnu_cxx::__normal_iterator > >) (in /home/serialk/prologin/a.out)
==4536== by 0x4020B0: int* std::__copy_move_a2 > >, int*>(__gnu_cxx::__normal_iterator > >, __gnu_cxx::__normal_iterator > >, int*) (in /home/serialk/prologin/a.out)
==4536== by 0x401FA6: int* std::copy \<__gnu_cxx::__normal_iterator const="" std::allocator="" std::vector=""> > >, int*>(__gnu_cxx::__normal_iterator > >, __gnu_cxx::__normal_iterator > >, int*) (in /home/serialk/prologin/a.out)
==4536== by 0x401DEA: int* std::__uninitialized_copy ::__uninit_copy \<__gnu_cxx::__normal_iterator const="" std::allocator="" std::vector=""> > >, int*>(__gnu_cxx::__normal_iterator > >, __gnu_cxx::__normal_iterator > >, int*) (in /home/serialk/prologin/a.out)
==4536== by 0x401B7A: int* std::uninitialized_copy \<__gnu_cxx::__normal_iterator const="" std::allocator="" std::vector=""> > >, int*>(__gnu_cxx::__normal_iterator > >, __gnu_cxx::__normal_iterator > >, int*) (in /home/serialk/prologin/a.out)
==4536== by 0x401797: int* std::__uninitialized_copy_a \<__gnu_cxx::__normal_iterator const="" std::allocator="" std::vector=""> > >, int*, int>(__gnu_cxx::__normal_iterator > >, __gnu_cxx::__normal_iterator > >, int*, std::allocator &) (in /home/serialk/prologin/a.out)
==4536== by 0x401488: std::vector >::vector(std::vector > const&) (in /home/serialk/prologin/a.out)
==4536== by 0x4011C7: Calcul(int, int*, std::vector >, std::vector >, int) (in /home/serialk/prologin/a.out)
==4536== by 0x4011FF: Calcul(int, int*, std::vector >, std::vector >, int) (in /home/serialk/prologin/a.out)
==4536== by 0x4011FF: Calcul(int, int*, std::vector >, std::vector >, int) (in /home/serialk/prologin/a.out)
==4536== If you believe this happened as a result of a stack
==4536== overflow in your program's main thread (unlikely but
==4536== possible), you can try to increase the size of the
==4536== main thread stack using the --main-stacksize= flag.
==4536== The main thread stack size used in this run was 8388608.
==4536== Stack overflow in thread 1: can't grow stack to 0x7fe801ff8
==4536==
==4536== Process terminating with default action of signal 11 (SIGSEGV)
==4536== Access not within mapped region at address 0x7FE801FF8
==4536== at 0x4A256B0: _vgnU_freeres (in /usr/lib/valgrind/vgpreload_core-amd64-linux.so)
==4536== If you believe this happened as a result of a stack
==4536== overflow in your program's main thread (unlikely but
==4536== possible), you can try to increase the size of the
==4536== main thread stack using the --main-stacksize= flag.
==4536== The main thread stack size used in this run was 8388608.
==4536==
==4536== HEAP SUMMARY:
==4536== in use at exit: 952,332 bytes in 47,620 blocks
==4536== total heap usage: 47,623 allocs, 3 frees, 952,348 bytes allocated
==4536==
==4536== LEAK SUMMARY:
==4536== definitely lost: 0 bytes in 0 blocks
==4536== indirectly lost: 0 bytes in 0 blocks
==4536== possibly lost: 0 bytes in 0 blocks
==4536== still reachable: 952,332 bytes in 47,620 blocks
==4536== suppressed: 0 bytes in 0 blocks
==4536== Rerun with --leak-check=full to see details of leaked memory
==4536==
==4536== For counts of detected and suppressed errors, rerun with: -v
==4536== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 2 from 2)
[1] 4536 segmentation fault (core dumped) valgrind ./a.out 2>&1 |

Tu noteras que l'outil t'affiche les endroits auxquels tu accèdes à la mémoire qui ne t'appartient pas, et, si tu compiles en debug, la ligne précise à laquelle ça arrive.

En particulier dans des langages bas-niveaux, regarder son code pendant longtemps n'aide pas énormément à comprendre ses problèmes, il faut absolument apprendre à se servir d'outils de debug, qui sont nécessaires pour développer efficacement.

C'est à vous de corriger les problèmes de votre code, même s'ils ont l'air de marcher chez vous, cela ne veut pas dire qu'ils marchent partout : ils peuvent contenir des comportements indéterminés, des fuites de mémoire, des erreurs de segmentation…

J'ai réussi à résoudre mon problème je mes suis tout simplement passer d'un pointeur et j'ai obtenu erreur mémoire dépasser,ce qui ma forcé à réécrire mon code et il fonctionne parfaitement .
Merci quand même pour l'aide mais actuellement je suis sous windows donc je ne pouvais de toute manière pas utiliser valgrind

Répondre au sujet

Vous devez vous enregistrer ou vous connecter pour poster des messages.