CS50,PSET5-Speller。运行valgrind时的错误帮助

时间:2020-05-09 06:51:49

标签: c dictionary valgrind cs50 spell-checking

我遇到以下错误。

==14574== Invalid read of size 1.
==14574==    at 0x4C33614: strcasecmp (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==14574==    by 0x40108C: check (dictionary.c:38)
==14574==    by 0x400C89: main (speller.c:113)

Looks like you're trying to access 1 byte of memory that isn't yours? Did you try to index into an array beyond its bounds? Take a closer look at line 38 of dictionary.c.

以下是我的代码块,其中包含第38行。

bool check(const char *word)
{
    node *cursor = hash_table[hash(word)];

    while (cursor != NULL)
    {
        if (strcasecmp(cursor -> word, word) == 0)  //This is line 38// 
        {
            return true;
        }
        cursor = cursor->next;
    }
    return false;
}

0 个答案:

没有答案