valgrind を実行すると、Conditional jump or move depends on uninitialised value(s)
メッセージが表示されます。
構造体配列へのポインターを割り当てましたが、この配列と関係があると思います。
struct nlist **hashtab;
void init(void)
{
hashtab = malloc(HASHSIZE * sizeof(*hashtab));
}
Valgrind メッセージ:
valgrind --tool=memcheck --track-origins=yes bin/Zuul
==3131== Conditional jump or move depends on uninitialised value(s)
==3131== at 0x400EF4: lookup (Dictionary.c:42)
==3131== by 0x400DDE: install (Dictionary.c:18)
==3131== by 0x4009A6: createItems (Game.c:42)
==3131== by 0x400901: main (Game.c:19)
==3131== Uninitialised value was created by a heap allocation
==3131== at 0x4C2757B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3131== by 0x400DB9: init (Dictionary.c:9)
==3131== by 0x4008FC: main (Game.c:16)
install()
は から呼び出される最初の関数でcreateItems()
、 を使用していhashtab
ます:
struct nlist *install(char *name, listItem *_item)
{
struct nlist *np;
unsigned hashval;
if ((np = lookup(name)) == NULL) {
np = malloc(sizeof(*np));
if (np == NULL || (np->name = strdupl(name)) == NULL)
return NULL;
hashval = hash(name);
np->next = hashtab[hashval];
np->_obj = _item;
hashtab[hashval] = np;
}
else
free((void *) np->_obj);
return np;
}
ルックアップ関数:
/* lookup: look for s in hashtab */
struct nlist *lookup(char *s)
{
struct nlist *np;
for (np = hashtab[hash(s)]; np != NULL; np = np->next)
if (strcmp(s, np->name) == 0)
return np;
return NULL;
}
hashtab
の後に dddの値を表示するinit()
: