[C] Erreur memoire (valgrind)

Fermé
Francky - 5 mars 2008 à 13:16
fiddy Messages postés 11069 Date d'inscription samedi 5 mai 2007 Statut Contributeur Dernière intervention 23 avril 2022 - 5 mars 2008 à 14:10
Bonjour,

Je suis en train de recoder un shell en C.
Je viens de terminer les alias, cela dit j'ai un probleme lorsque je lance valgrind.

Il me fait :
==1669== Conditional jump or move depends on uninitialised value(s)
==1669== at 0x8048B34: my_strcmp (in ./mysh)
==1669== by 0x8048997: alias (in ./mysh)
==1669== by 0x8049504: pre_command (in ./mysh)
==1669== by 0x8048884: mishi_runner (in ./mysh)
==1669==
==1669== Conditional jump or move depends on uninitialised value(s)
==1669== at 0x8048A14: alias (in ./mysh)
==1669== by 0x8049504: pre_command (in ./mysh)
==1669== by 0x8048884: mishi_runner (in ./mysh)
==1669== by 0x8048910: main (in ./mysh)

voici les bouts de code concernes :

func pre-command
void    pre_command(char *str)
{
  if (str[0] != 10)
    select_command(alias(str));
  else
    select_command(str);
}


func alias
char    *alias(char *alias)
{
  char  *command;
  int   fd;
  char  *buf;
  int   count;
  int   count2;

  buf = xmalloc(sizeof(*buf) * SMAX);
  command = xmalloc(sizeof(*command) * 32);
  fd = xopen(".mishirc", O_RDONLY);
  xread(fd, buf, SMAX);
  count = 0;
  while (buf[count] != 0)
    {
      if (my_strcmp(buf, "alias ", count, 0, 6) == 1
          && my_strcmp(buf, alias, count + 6, 0, my_strlen(alias, 0, 10)) == 1)


func my_strcmp
int     my_strcmp(char *str, char *str2, int count, int count2, int end)
{
  int   res;

  res = 1;
  while (end != 0)
    {
      if (str[count] != str2[count2])
        res = 0;
      count++;
      count2++;
      end--;
    }
  return (res);
}


Euh voili voilou , je ne comprend pas du tout l'erreur de Valgrind car toutes les variables qui se baladent ont ete initialise... non ?

Mici
A voir également:

1 réponse

fiddy Messages postés 11069 Date d'inscription samedi 5 mai 2007 Statut Contributeur Dernière intervention 23 avril 2022 1 844
5 mars 2008 à 14:10
Salut,

Dans ta fonction alias, la variable buf n'est pas initialisée. Tu as juste fait l'allocation.

Cordialement
1