Valgrind Conditional jump obscure
Bonjour à tous et merci d'avance
J'ai un lèger problème avec une de mes fonctions qui produit des erreurs valgrind mais n'empêche pas le bon fonctionnement du programme.
Une de me fonctions qui check la présence d'un binaire dans les dossiers de la variable PATH de l'environnement et à priori je doit mal utiliser les fonctions systèmes.
Je ne demande pas que l'on me résoude le problème en me donnant la réponse ce ne serait pas intéressant ne serait-ce que pour l'apprentissage.
Si vous avez des pistes ou de la doc vers laquelle me rediger je suis preneur par contre.
Je compile avec -g et avec la commande valgrind suivante j'obtiens cette érreur.
Citation:
valgrind --track-origins=yes ./prog-dbg
Citation:
==7816== Conditional jump or move depends on uninitialised value(s)
==7816== at 0x400F6E: my_access (get_path.c:48)
==7816== by 0x400EA5: get_path (get_path.c:28)
==7816== by 0x400B39: execute (execute.c:25)
==7816== by 0x4012FC: launch (launch.c:27)
==7816== by 0x400A32: main (main.c:27)
==7816== Uninitialised value was created by a stack allocation
==7816== at 0x400F1A: my_access (get_path.c:42)
Voilà les sources.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
// fonction retournant le path associé au binaire (ex: pour ls -> /bin/ls)
char *get_path(char *bin, char **ae)
{
char *path;
char **tab_path;
int i;
i = 0;
if ((ae[0] != NULL) && (bin != NULL))
{
path = my_getenv("PATH=", ae) + 5;
tab_path = str_to_word_tab(path, ':');
while (tab_path[i] != NULL)
{
// my_strcat concatène les deux chaînes de caractere dans une nouvelle chaîne qu'il alloue
tab_path[i] = my_strcat(tab_path[i], "/");
path = my_strcat(tab_path[i], bin);
if (my_access(path) == 0)
{
free_all("%t", tab_path); // free le tableau
return (path);
}
i++;
}
my_printf("Command not found\n");
free_all("%t", tab_path); // free le tableau
}
return (NULL);
}
// ici le but est de tester la présence du binaire donné par la variable path
int my_access(char *path)
{
struct stat sb;
if (path == NULL)
return (-1);
stat(path, &sb);
if ((sb.st_mode & S_IFDIR) == S_IFDIR)
return (-1);
if (access(path, X_OK) == -1)
return (-1);
return (0);
} |
A priori le problème viendrai des lignes suivantes qui quand ont les enlève ne pètent plus de Conditional Jump:
Code:
1 2
| if ((sb.st_mode & S_IFDIR) == S_IFDIR)
return (-1); |