Bonjour à tous,
Je dois rendre un Compte Rendu de TP ce soir par Mail, et j'ai un programme qui marche nickel mais il y a un petit problème de *** stack smashing detected *** !!! et ça fait un peu moche ^^.
donc mon programme c'est ça:
(je précise que stringCrossCopyN(dest,N,source) prend le mot pointer par source et inverse tout les lettres par exemple Babar -> rabaB et rabaB sera pointé par dest. N sert a limitée le nombre de lettre inversé par exemple si N=5 ça fera ça : Babar -> raba. stringCrossCopy(dest,source) ca fait pareil sauf que il n'y a pas de limite il fera le traitement sur le mot en entier. )
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 #include <stdio.h> #include <stdlib.h> #include <string.h> #include "charUtil.h" int main (int argc, char *argv[]) { int A=0; int k=0; const char* src; char* dest; char tab1[9]={0}; char tab2[9]={0}; int length; if(strcmp(argv[1],"1")==0) A=1; else if(strcmp(argv[1],"2")==0) A=2; if(A==1) { nomPrint("progChaines"); for(k=1;k<argc;k++) nomPrint(argv[k]); nomPrint("Donald"); nomPrint("Babar"); } if(A==2) { dest=&tab2[0]; src="Babar"; stringCrossCopyN(dest,10,src); printf("%s -> %s\n",src,dest); stringCrossCopy(dest,src); printf("%s -> %s\n",src,dest); src="Donald"; stringCrossCopyN(dest,10,src); printf("%s -> %s\n",src,dest); stringCrossCopy(dest,src); printf("%s -> %s\n",src,dest); while(k<argc) { src=argv[k]; stringCrossCopyN(dest,10,src); printf("%s -> %s\n",src,dest); stringCrossCopy(dest,src); printf("%s -> %s\n",src,dest); k++; } printf("salut c'est fini."); } return EXIT_SUCCESS; }
voilà donc comme ça le programme marche nickel mais je sais pas si vous l'avez remarqué, tab1 est inutilisé (et il me le dit a la compilation) mais si :
- je le supprime
- je change sa taille
et que après je le compile et j'exécute progChaines 2, il fait le programme normalement presque jusqu'au bout puis j'ai tout le *** stack smashing detected *** et il écrit a la fin "salut c'est fini." puis il fini par écrire abandon. si j'exécute progChaines 1 ça marche nickel le programme 1.
Si je renomme tab1 en ce que je veux du genre test ou ce que je veux et ben le programme s'exécute normalement et pas de *** stack smashing detected *** mais j'ai toujours a la compilation le message disant que test est inutilisé.
je vous met un exemple de l'exécution avec le *** stack smashing detected *** :
je précise que les procédures se trouve dans un autre fichier. charUtil.c et que il y a les prototypes des fonctions dans charUtil.h
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 desktop:~/Documents/TP/TP3$ make gcc -g -c -Wall -pedantic main.c gcc -lm main.o charUtil.o -o progChaines desktop:~/Documents/TP/TP3$ ./progChaines 2 tata totoldkeiejkfgf Babar -> rabaB Babar -> rabaB Donald -> dlanoD Donald -> dlanoD ./progChaines -> seniahCgo ./progChaines -> seniahCgorp/. 2 -> 2 2 -> 2 tata -> atat tata -> atat totoldkeiejkfgf -> fgfkjeiek totoldkeiejkfgf -> fgfkjeiekdlotot *** stack smashing detected ***: ./progChaines terminated ======= Backtrace: ========= /lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x48)[0xb7f42558] /lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x0)[0xb7f42510] ./progChaines[0x804890f] /lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe5)[0xb7e5e685] ./progChaines[0x80484e1] ======= Memory map: ======== 08048000-08049000 r-xp 00000000 08:02 271749 /home/bernard/Documents/TP/TP3/progChaines 08049000-0804a000 r--p 00000000 08:02 271749 /home/bernard/Documents/TP/TP3/progChaines 0804a000-0804b000 rw-p 00001000 08:02 271749 /home/bernard/Documents/TP/TP3/progChaines 08632000-08653000 rw-p 08632000 00:00 0 [heap] b7e2a000-b7e37000 r-xp 00000000 08:02 48734 /lib/libgcc_s.so.1 b7e37000-b7e38000 r--p 0000c000 08:02 48734 /lib/libgcc_s.so.1 b7e38000-b7e39000 rw-p 0000d000 08:02 48734 /lib/libgcc_s.so.1 b7e47000-b7e48000 rw-p b7e47000 00:00 0 b7e48000-b7fa0000 r-xp 00000000 08:02 66234 /lib/tls/i686/cmov/libc-2.8.90.so b7fa0000-b7fa2000 r--p 00158000 08:02 66234 /lib/tls/i686/cmov/libc-2.8.90.so b7fa2000-b7fa3000 rw-p 0015a000 08:02 66234 /lib/tls/i686/cmov/libc-2.8.90.so b7fa3000-b7fa6000 rw-p b7fa3000 00:00 0 b7fa6000-b7fca000 r-xp 00000000 08:02 66242 /lib/tls/i686/cmov/libm-2.8.90.so b7fca000-b7fcb000 r--p 00023000 08:02 66242 /lib/tls/i686/cmov/libm-2.8.90.so b7fcb000-b7fcc000 rw-p 00024000 08:02 66242 /lib/tls/i686/cmov/libm-2.8.90.so b7fd9000-b7fdc000 rw-p b7fd9000 00:00 0 b7fdc000-b7ff6000 r-xp 00000000 08:02 48691 /lib/ld-2.8.90.so b7ff6000-b7ff7000 r-xp b7ff6000 00:00 0 [vdso] b7ff7000-b7ff8000 r--p 0001a000 08:02 48691 /lib/ld-2.8.90.so b7ff8000-b7ff9000 rw-p 0001b000 08:02 48691 /lib/ld-2.8.90.so bfbe4000-bfbf9000 rw-p bffeb000 00:00 0 [stack] salut c'est fini.Abandon
le makefile que j'utilise est le suivant:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 progChaines : main.o charUtil.o gcc -lm main.o charUtil.o -o progChaines main.o : main.c gcc -g -c -Wall -pedantic main.c charUtil.o : charUtil.c charUtil.h gcc -g -c -Wall -pedantic charUtil.c
Je reprécise que c'est trés pressant donc si vous pouviez me répondre dans les plus brefs délais ce serait sympa sachant que ce n'est pas un programme trés complexe.^^
Merci d'Avance.
A+ Matt
pour ce qui veulent jeter un coup d'oeil à charUtil.c :
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97 #include <string.h> #include "charUtil.h" /*----------------------------------------------------------------------*/ /* Nom : asciiCharToString */ /* But : Cree dans un buffer (à l'aide de snprintf une chaîne comportant un caractere ascii, son code en hexadecimal et son code en décimal selon le format exact : (pour le caractère 0) Caractere : <0>, valeur hexadecimale : 0x30, valeur decimale : 48. Paramètres : buf, size : le buffer et sa taille c: valeur du caractere a afficher Valeur rendue : --- Précondition : Postcondition : ----------------------------------------------------------------------*/ static void asciiCharToString(char* buf, int size, const char c ) { (void)snprintf(buf,size,"Caractere : <%c>, valeur hexadecimale : 0x%x, valeur decimale : %3d.\n", c, c, c) ; } void asciiCharPrint(const char c ) { char buf[256] ; asciiCharToString(buf,sizeof(buf), c) ; (void)fprintf(stdout, "%s",buf); } void nomPrint(const char *nom) { char length=0; int i=0; int j,k; char tab[50]; const char* A=nom; while( *A != '\0') { length++; tab[i++]=*A; A++; } printf("(%d) ",length); for(k=0;k<i;k++) printf("%c",tab[k]); printf("\n"); for(j=0;j<i;j++) asciiCharPrint(tab[j]); } void stringCrossCopy(char* destination, const char* source) { char length=0; char *a=destination; char *b=source; int i=0; char z; while( *b != '\0' ) { length++; b++; } while (i<length) { b=source+i; a=destination+length-i-1; z=*b; *a=z; i++; } *(a+length)='\0'; } void stringCrossCopyN(char* destination, int size, const char* source) { char length=0; char *a=destination; char *b=source; int i=0; char z; while( *b != '\0' ) { length++; b++; } if (length<size-1) stringCrossCopy(destination,source); else { while(i<size-1) { b=source+length-1-i; a=destination+i; z=*b; *a=z; i++; } *(a+1)='\0'; } }
Partager