I amnew to valgrind and I'm trying to figure out what this error means in my program in terms of what valgrind is stating.A little background on the program, I am writing a program that reads in a text file and dictionary file. The text file is compared to the dictionary file, and if a word from the text file does not match a word in the dictionary file, the word is considered misspelled and is displayed within the console. Here is the valgrind output I am getting when I run my program(note that line 141 is the for loop where I traverse through the hash table).
==13685== Invalid read of size 4
==13685== at 0x8049249: check (dictionary.c:141)
==13685== by 0x8048BCF: main (speller.c:115)
==13685== Address 0x30 is not stack'd, malloc'd or (recently) free'd
==13685==
==13685==
==13685== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==13685== Access not within mapped region at address 0x30
==13685== at 0x8049249: check (dictionary.c:141)
==13685== by 0x8048BCF: main (speller.c:115)
==13685== If you believe this happened as a result of a stack
==13685== overflow in your program's main thread (unlikely but
==13685== possible), you can try to increase the size of the
==13685== main thread stack using the --main-stacksize= flag.
==13685== The main thread stack size used in this run was 8388608.
==13685==
And here is the function that is the culprit of this error:
Code:
int i=0;
char DuplicateArray[45];
int sizevalue=0;
Node* NodePointer=NULL;
unsigned int hashval=0;
int counter=0;
sizevalue =sizeof(word);
strncpy(&DuplicateArray[counter], word,sizevalue);
DuplicateArray[sizevalue-1] = '\0';
hashval=hash(DuplicateArray);
for (NodePointer=hashtable->table[hashval];NodePointer !=NULL;NodePointer=NodePointer->Next)
{
i=strcmp(DuplicateArray,NodePointer->word);
if (i==0)
{
return true;
}
else
NodePointer =NodePointer->Next;
}
return false;
}
Does anyone have any any suggestions on what might be the problem and what valgrind is telling me? Also, if I need to incude more code, please let me know. Thanks.