IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 C++ Discussion :

erreur : "glibc detected" à l'exécution


Sujet :

C++

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    219
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations forums :
    Inscription : Janvier 2009
    Messages : 219
    Points : 97
    Points
    97
    Par défaut erreur : "glibc detected" à l'exécution
    Bonjour à tous,

    J'obtiens une erreur (que je n'avais jamais vue) lorsque je fais appel à une fonction d'affichage. Cette erreur a lieu lors de l'exécution, pas lors de la compilation.
    Voici une partie de l'erreur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
     
    *** glibc detected *** ./projet: free(): invalid pointer: 0x0804e9ac ***
    ======= Backtrace: =========
    /lib/libc.so.6[0x2147e4]
    /lib/libc.so.6(cfree+0x96)[0x216846]
    /usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0x340a461]
    /usr/lib/libstdc++.so.6(_ZNSs4_Rep10_M_destroyERKSaIcE+0x1d)[0x33e62cd]
    /usr/lib/libstdc++.so.6(_ZNSsD1Ev+0x63)[0x33e7b33]
    ./projet[0x8049d0a]
    ./projet[0x8049d9f]
    ./projet[0x8049ecd]
    ./projet[0x8049f41]
    ./projet[0x8049371]
    ./projet[0x804be68]
    /lib/libc.so.6(__libc_start_main+0xe6)[0x1bd5d6]
    ./projet(__gxx_personality_v0+0x5d)[0x8048e31]
    ======= Memory map: ========
    00110000-00111000 r-xp 00110000 00:00 0          [vdso]
    00187000-001a3000 r-xp 00000000 08:03 22532      /lib/ld-2.8.so
    001a3000-001a4000 r--p 0001c000 08:03 22532      /lib/ld-2.8.so
    001a4000-001a5000 rw-p 0001d000 08:03 22532      /lib/ld-2.8.so
    001a7000-0030a000 r-xp 00000000 08:03 22538      /lib/libc-2.8.so
    0030a000-0030c000 r--p 00163000 08:03 22538      /lib/libc-2.8.so
    0030c000-0030d000 rw-p 00165000 08:03 22538      /lib/libc-2.8.so
    0030d000-00310000 rw-p 0030d000 00:00 0
    Et voici la fonction en question :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
    void stafflist::PrintStaffList(){ //lecture de 4 mots dans un fichier
     
    ifstream fichier( "staff.txt" );
     
        if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
        {
    	int var1; 
    	string var2;
    	string var3;
    	string var4;
    	fichier >> var1 >> var2 >> var3 >> var4; 
    	fichier.close();  
        }
        else  
    	cout << "Impossible d'ouvrir le fichier !" << endl;
     
        }
    Pouvez-vous me dire ce que signifie cette erreur? Il est question de pointeur, mais je n'en utilise pas ...

  2. #2
    Membre éclairé
    Avatar de Florian Goo
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    680
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Septembre 2008
    Messages : 680
    Points : 858
    Points
    858
    Par défaut
    Bonjour à toi,

    Chez moi ça marche :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
     
    #include <fstream>
    #include <iostream>
     
    using namespace std;
     
    int main()
    {
    	ifstream fichier( "staff.txt" );
     
        if(fichier) // ce test échoue si le fichier n'est pas ouvert
        {
    		int var1; 
    		string var2;
    		string var3;
    		string var4;
    		fichier >> var1 >> var2 >> var3 >> var4;
     
    		cout << var1 << " " << var2 << " " << var3 << " " << var4 << endl;
     
    		fichier.close();  
        }
        else
    	{
    		cout << "Impossible d'ouvrir le fichier !" << endl;
        }
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    florian@flobox:~/Développement/test$ cat staff.txt 
    998 auiee auuuuaie ei
    florian@flobox:~/Développement/test$ g++ main.cpp
    florian@flobox:~/Développement/test$ ./a.out 
    998 auiee auuuuaie ei
    florian@flobox:~/Développement/test$
    Le problème doit venir d'ailleurs…
    Cours : Initiation à CMake
    Projet : Scalpel, bibliothèque d'analyse de code source C++ (développement en cours)
    Ce message a été tapé avec un clavier en disposition bépo.

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    219
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations forums :
    Inscription : Janvier 2009
    Messages : 219
    Points : 97
    Points
    97
    Par défaut
    ok, merci!
    J'ai regardé ailleurs, et j'avais un problème quand je choisissais d'afficher ma liste. L'erreur a disparue, mais ma fonction ne marche toujours pas chez moi et maintenant j'obtiens des erreurs à la compilation :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    stafflist.cc: In member function ‘void stafflist::PrintStaffList()’:
    stafflist.cc:110: erreur: no match foroperator>>’ in ‘fichier.std::basic_ifstream<char, std::char_traits<char> >::<anonymous>.std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((int&)(& var1))) >> ""’
    /usr/lib/gcc/i386-redhat-linux/4.3.0/../../../../include/c++/4.3.0/istream:123: note: candidats sont: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>& (*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
    D'où cela peut-il venir?
    J'appelle ma fonction ainsi :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    stafflistobject.PrintStaffList();
    où stafflistobject est un objet de la classe stafflist

  4. #4
    Membre éclairé
    Avatar de Florian Goo
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    680
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Septembre 2008
    Messages : 680
    Points : 858
    Points
    858
    Par défaut
    L'erreur ne vient pas de la façon dont tu appelles ta fonction, mais du contenu de la fonction elle-même !
    Plus précisément, l'erreur se trouve à la ligne 110 du fichier stafflist.cc. À quoi cela correspond-il ?
    Cours : Initiation à CMake
    Projet : Scalpel, bibliothèque d'analyse de code source C++ (développement en cours)
    Ce message a été tapé avec un clavier en disposition bépo.

  5. #5
    Membre régulier
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    219
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations forums :
    Inscription : Janvier 2009
    Messages : 219
    Points : 97
    Points
    97
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
     
    void stafflist::PrintStaffList(){
     
    cout<<"12\n";
    ifstream fichier( "staff.txt" );
    cout<<"0";
        if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
        {
            // cette boucle s'arrête dès qu'une erreur de lecture survient
            //while (getline( fichier, line ) )
            //{
    	cout<<"1";
    	int var1; 
    	string var2;
    	string var3;
    	string var4;
    	//string line;
    	fichier >> var1 >> "">> var2 >>"" >>var3 >> "">>var4; ////ligne 110/////
                // afficher la ligne à l'écran
            //std::cout << line << std::endl;
    	//staff personneajouter(var1,var2,var3,var4);
    	//mylistofstaff.push_back(personneajouter);
           // }
    	fichier.close();  
        }
        else  
    	{cout << "Impossible d'ouvrir le fichier !" << endl;}
     
     }

  6. #6
    Rédacteur

    Avatar de Matthieu Brucher
    Profil pro
    Développeur HPC
    Inscrit en
    Juillet 2005
    Messages
    9 810
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Développeur HPC
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2005
    Messages : 9 810
    Points : 20 970
    Points
    20 970
    Par défaut
    C'est quoi les "" qui se baladent ? Comment veux-tu mettre un résultat dans un chaîne de caractères constantes ?

  7. #7
    Membre régulier
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    219
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations forums :
    Inscription : Janvier 2009
    Messages : 219
    Points : 97
    Points
    97
    Par défaut
    C'était effectivement ces guillemets ! Merci bcp pour votre aide!
    A priori, ma fonction marche bien maintenant

  8. #8
    Membre régulier
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    219
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations forums :
    Inscription : Janvier 2009
    Messages : 219
    Points : 97
    Points
    97
    Par défaut
    Il reste un dernier problème "d'affichage" lorsque j'appelle cette fonction.
    Ma fonction :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
     
    void stafflist::PrintStaffList(){
    string line;
    ifstream fichier( "staff.txt" );
     
        if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
        {
            while (!fichier.eof() )
            {
    	int var1; 
    	string var2;
    	string var3;
    	string var4;
     
    	fichier >> var1 >> var2 >>var3 >> var4; 
    	staff personneajouter(var1,var2,var3,var4);
    	mylistofstaff.push_back(personneajouter);
            }
    	fichier.close();  
        }
        else  
    	{cout << "Impossible d'ouvrir le fichier !" << endl;}
     
     
    for (list<staff>::iterator it = mylistofstaff.begin (); it != mylistofstaff.end (); ++it) {
    std::cout << " Number : " << it->getIdent()<<  " Name : " << it->getNameStaff() << " Organiser : " << it->getVornameStaff()<< " Departement organiser : " << it->getDepartStaff() <<endl;
    }
     
     }
    Voici la liste que je veux afficher,qui se trouve dans staff.txt

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    1 Baliki Florian DepartementofComputerScience
    2 Dumont Pierre DepartementofComputerScience
    3 Dupont Martinne DepartementofSignalProcessing
    4 Martin Paul DepartementofSoftwareSystems
    5 Merle Aurélie DepartementofMathematics
    6 Novak Michal DepartementofLogistics
    7 Pichet Robert DepartementofMathematics
    8 Pradel Constance DepartementofCommunicationsEngineering
    9 Pradel Jacques DepartementofEnvironment
    10 Siltanen Samuli DepartementofPhysics
    11 Turunen Esko DepartementofMathematics
    Et voici ce qui sort :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
      Number : 1 Name : Baliki Organiser : Florian Departement organiser : DepartementofComputerScience
     Number : 2 Name : Dumont Organiser : Pierre Departement organiser : DepartementofComputerScience
     Number : 3 Name : Dupont Organiser : Martinne Departement organiser : DepartementofSignalProcessing
     Number : 4 Name : Martin Organiser : Paul Departement organiser : DepartementofSoftwareSystems
     Number : 5 Name : Merle Organiser : Aurélie Departement organiser : DepartementofMathematics
     Number : 6 Name : Novak Organiser : Michal Departement organiser : DepartementofLogistics
     Number : 7 Name : Pichet Organiser : Robert Departement organiser : DepartementofMathematics
     Number : 8 Name : Pradel Organiser : Constance Departement organiser : DepartementofCommunicationsEngineering
     Number : 9 Name : Pradel Organiser : Jacques Departement organiser : DepartementofEnvironment
     Number : 10 Name : Siltanen Organiser : Samuli Departement organiser : DepartementofPhysics
     Number : 11 Name : Turunen Organiser : Esko Departement organiser : DepartementofMathematics
     Number : 11 Name :  Organiser :  Departement organiser :  ///?????///
    Pourquoi cette dernière ligne apparait-elle? Est-ce que j'appelle mon itérateur trop de fois?

  9. #9
    Membre éclairé
    Avatar de Florian Goo
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    680
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Septembre 2008
    Messages : 680
    Points : 858
    Points
    858
    Par défaut
    J'ai jeté un œil très rapide, mais ta boucle for m'a l'air bonne. Je pense plutôt que ça vient du while.
    Cours : Initiation à CMake
    Projet : Scalpel, bibliothèque d'analyse de code source C++ (développement en cours)
    Ce message a été tapé avec un clavier en disposition bépo.

  10. #10
    Membre chevronné
    Avatar de Goten
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    1 580
    Détails du profil
    Informations personnelles :
    Âge : 33
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 580
    Points : 2 205
    Points
    2 205
    Par défaut
    Quoiqu'il en soit tu tests la fin sur eof() ce qu'il ne faut pas faire. cf la faq pour avoir plus de détails!

    Pour le for, c'est une bonne pratique que de tester la condition de sortie sur un ensemble plutôt que sur une valeur.
    "Hardcoded types are to generic code what magic constants are to regular code." --A. Alexandrescu

  11. #11
    Expert confirmé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2003
    Messages
    3 549
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 3 549
    Points : 4 625
    Points
    4 625
    Par défaut
    Erreur mémoire.
    Comme d'habitude, valgrind est ton ami.
    Boost ftw

  12. #12
    Membre régulier
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    219
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations forums :
    Inscription : Janvier 2009
    Messages : 219
    Points : 97
    Points
    97
    Par défaut
    Le problème venait bien de while (!fichier.eof() ). Voilà une solution au problème (si ça peut aider quelqu'un un jour ...) :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
    void Stafflist::PrintStaffList(){
    string line;
    ifstream fichier( "staff.txt" );
    int var1; 
    string var2;
    string var3;
    string var4;
        if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
        {
            while ( fichier >> var1 && fichier >> var2 && fichier >>var3 && fichier >> var4 )
            {
     
    	Staff personneajouter(var1,var2,var3,var4);
    	mylistofstaff.push_back(personneajouter);
            }
    	fichier.close();  
        }
        else  
    	{cout << "Impossible d'ouvrir le fichier !" << endl;}
     
    }
    Merci à tous

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Erreur : glibc detected
    Par L8O8L dans le forum C
    Réponses: 3
    Dernier message: 04/03/2008, 07h22
  2. erreur glibc detected double free or corruption.
    Par Screwt-K dans le forum C++
    Réponses: 1
    Dernier message: 02/07/2007, 16h46

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo