bonjour,
J'ai un petit souci : je suis en train de programmer la fonction malloc et free de la lib c tout en utilisant mmap, et j'ai fini la fonction malloc et la j'attaque la fonction free mais ce que je comprend pas : c'est dans les messages suivants :
mon code de la fct free :1 - warning: junk pointer, too high to make sense.
2 - warning: junk pointer, too low to make sense.
mon problem c est que a chaque fois j appel la fct free(ma variable)
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 void *find_last_block(void) { s_block *tmp = g_list; void *p = NULL; char *str = NULL; while (tmp && tmp->next) tmp = tmp->next; p = tmp; str = p; str += sizeof (s_block) + tmp->truesize + 1; p = str; return (p); } void free(void *ptr) { s_block *tm = ptr; tm = find_block(ptr); if (tm == NULL || ptr == NULL) return; if (tm->free == 1) print_error("warning: chunk is already free.\n"); if (tm->ptr > find_last_block()) { print_error("warning: junk pointer, too high to make sense.\n"); return; } if (tm->ptr != ptr) { print_error("warning: modified chunk-pointer.\n"); return; } if (ptr < g_list->ptr) { print_error("warning: junk pointer, too low to make sense.\n"); return; } tm->free = 1; }
il m'affichie
J'aimerai savoir si c'est moi qui n'ai rien compris de la fonction free et ses erreurs sinon j'aimerai bien que quelqu'un m'explique soit le comportement et pourquoi pas comment je dois faireNBR1 : 0x7f23e6d60030
free NBR1
warning: junk pointer, too low to make sense.
X : 0x7f23e6d66030
free X
warning: junk pointer, too high to make sense.
merci d'avance ^^
Partager