Citation:
==11432== Conditional jump or move depends on uninitialised value(s)
==11432== at 0x8048B62: count_str (cp_buff_to_tab.c:22)
==11432== by 0x8048B86: cp_buff_to_tab (cp_buff_to_tab.c:41)
==11432== by 0x80487D8: main (main.c:45)
==11432==
==11432== Conditional jump or move depends on uninitialised value(s)
==11432== at 0x80489B7: my_strlen (functions.c:38)
==11432== by 0x8048BDA: cp_buff_to_tab (cp_buff_to_tab.c:51)
==11432== by 0x80487D8: main (main.c:45)
==11432==
==11432== Invalid write of size 4
==11432== at 0x8048C75: cp_buff_to_tab (cp_buff_to_tab.c:59)
==11432== by 0x80487D8: main (main.c:45)
==11432== Address 0x3C11641C is 4 bytes inside a block of size 5 alloc'd
==11432== at 0x3C03418B: malloc (in /usr/local/lib/valgrind/vgpreload_memcheck.so)
==11432== by 0x8048B96: cp_buff_to_tab (cp_buff_to_tab.c:41)
==11432== by 0x80487D8: main (main.c:45)
Code:
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 char **cp_buff_to_tab(char *str) { char **tab; int count; int i; int j; i = 0; count = 0; tab = malloc(sizeof(*tab) * count_str(str) + 1); while (str[count] != '\0' && str[count] != '\n') { if (str[count] == ' ' || str[count] == '\n') { count++; i++; } else { tab[i] = malloc(sizeof(**tab) * my_strlen(str)); j = 0; while (str[count] != ' ' && str[count] != '\0' && str[count] != '\n') tab[i][j++] = str[count++]; tab[i][j] = '\0'; } } i = i + 1; tab[i] = 0; return (tab); }