Bonjour !
J'ai besoin de votre aide pour une erreur que je rencontre lorsque je veux "stocker" un objet dans un fichier.
Le code est assez simple, je crée un profil, je l'écris sur mon fichier. Ensuite, je veux ré-ouvrir ce même fichier, le lire et afficher le login du profil.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 int main() { Profile p("pazze", "0101", "aure", "blabla", "27/06/1990"); File f; f.createFileProfile(p); cout << (f.readFileProfile("pazze")).getLogin() << endl; return 0; }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 void File::createFileProfile(Profile p) { string name = p.getLogin(); int fileProfile ; if ((fileProfile = open(name.c_str(), O_WRONLY | O_TRUNC | O_CREAT ,0700 )) == -1) cout << "File : Erreur dans la création du fichier de profil" << endl; if (write(fileProfile, &p, sizeof(Profile)) == -1) cout << "File : Erreur dans l'écriture du profil" << endl; close(fileProfile); }Le message d'erreur que j'obtiens est le suivant (du charabiat pour moi
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 Profile File::readFileProfile(string login) { int fp; Profile q; if((fp = open(login.c_str(), O_RDONLY)) == -1) cout << "Serveur : Le fichier demandé n'existe pas" << endl; else if (read (fp, &q, sizeof(Profile)) == -1) cout << "File : Erreur dans la lecture de profil" << endl; close(fp); return q; }) :
un ptit coup de gdb si ça peut aider :*** glibc detected *** ./test: double free or corruption (fasttop): 0x09a8a008 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6[0xb7ea9604]
/lib/tls/i686/cmov/libc.so.6(cfree+0x96)[0xb7eab5b6]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xb808c231]
/usr/lib/libstdc++.so.6(_ZNSs4_Rep10_M_destroyERKSaIcE+0x1d)[0xb80689fd]
/usr/lib/libstdc++.so.6(_ZNSsD1Ev+0x51)[0xb806a3b1]
./test[0x8048fee]
./test[0x804ab94]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe5)[0xb7e50775]
./test[0x8048a91]
======= Memory map: ========
08048000-0804c000 r-xp 00000000 08:05 737527 /home/aurelien/Bureau/Projet à jour/test
0804c000-0804d000 r--p 00003000 08:05 737527 /home/aurelien/Bureau/Projet à jour/test
0804d000-0804e000 rw-p 00004000 08:05 737527 /home/aurelien/Bureau/Projet à jour/test
09a8a000-09aab000 rw-p 09a8a000 00:00 0 [heap]
b7d00000-b7d21000 rw-p b7d00000 00:00 0
b7d21000-b7e00000 ---p b7d21000 00:00 0
b7e39000-b7e3a000 rw-p b7e39000 00:00 0
b7e3a000-b7f96000 r-xp 00000000 08:05 3228507 /lib/tls/i686/cmov/libc-2.9.so
b7f96000-b7f97000 ---p 0015c000 08:05 3228507 /lib/tls/i686/cmov/libc-2.9.so
b7f97000-b7f99000 r--p 0015c000 08:05 3228507 /lib/tls/i686/cmov/libc-2.9.so
b7f99000-b7f9a000 rw-p 0015e000 08:05 3228507 /lib/tls/i686/cmov/libc-2.9.so
b7f9a000-b7f9d000 rw-p b7f9a000 00:00 0
b7f9d000-b7faa000 r-xp 00000000 08:05 3211397 /lib/libgcc_s.so.1
b7faa000-b7fab000 r--p 0000c000 08:05 3211397 /lib/libgcc_s.so.1
b7fab000-b7fac000 rw-p 0000d000 08:05 3211397 /lib/libgcc_s.so.1
b7fac000-b7fad000 rw-p b7fac000 00:00 0
b7fad000-b7fd1000 r-xp 00000000 08:05 3228515 /lib/tls/i686/cmov/libm-2.9.so
b7fd1000-b7fd2000 r--p 00023000 08:05 3228515 /lib/tls/i686/cmov/libm-2.9.so
b7fd2000-b7fd3000 rw-p 00024000 08:05 3228515 /lib/tls/i686/cmov/libm-2.9.so
b7fd3000-b80b7000 r-xp 00000000 08:05 6979749 /usr/lib/libstdc++.so.6.0.10
b80b7000-b80bb000 r--p 000e3000 08:05 6979749 /usr/lib/libstdc++.so.6.0.10
b80bb000-b80bc000 rw-p 000e7000 08:05 6979749 /usr/lib/libstdc++.so.6.0.10
b80bc000-b80c2000 rw-p b80bc000 00:00 0
b80da000-b80dd000 rw-p b80da000 00:00 0
b80dd000-b80de000 r-xp b80dd000 00:00 0 [vdso]
b80de000-b80fa000 r-xp 00000000 08:05 3211283 /lib/ld-2.9.so
b80fa000-b80fb000 r--p 0001b000 08:05 3211283 /lib/ld-2.9.so
b80fb000-b80fc000 rw-p 0001c000 08:05 3211283 /lib/ld-2.9.so
bfb9b000-bfbb0000 rw-p bffeb000 00:00 0 [stack]
AbandonL'erreur vient selon moi du read, mais sans aucune certitude. Et surtout, je ne comprend pas pourquoi !Program received signal SIGABRT, Aborted.
0xb80bc430 in __kernel_vsyscall ()
(gdb) where
#0 0xb80bc430 in __kernel_vsyscall ()
#1 0xb7e446d0 in raise () from /lib/tls/i686/cmov/libc.so.6
#2 0xb7e46098 in abort () from /lib/tls/i686/cmov/libc.so.6
#3 0xb7e8224d in ?? () from /lib/tls/i686/cmov/libc.so.6
#4 0xb7e88604 in ?? () from /lib/tls/i686/cmov/libc.so.6
#5 0xb7e8a5b6 in free () from /lib/tls/i686/cmov/libc.so.6
#6 0xb806b231 in operator delete () from /usr/lib/libstdc++.so.6
#7 0xb80479fd in std::string::_Rep::_M_destroy () from /usr/lib/libstdc++.so.6
#8 0xb80493b1 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string () from /usr/lib/libstdc++.so.6
#9 0x08048fee in Profile::~Profile ()
#10 0x0804ab94 in main ()
Vous avez une idée ?
Merci![]()
Partager