It seems you're not supplying all of the relevant code.
As nonsensical as your assertion sounds, that malloc modifies unrelated memory - I whipped up a quick test. There is no such behaviour exhibited.
I notice that you set hashValue to be equal to _word. Can't help but wonder if you're modifying *hashValue (which obviously or not, will modify *_word)
Here's the code I compiled and the output:
Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct _DocumentNode
{
struct _DocumentNode *next;
int document_id;
int page_word_frequency;
} __DocumentNode;
typedef struct _DocumentNode DocumentNode;
int update_Index(int documentID,char *_word)
{
{
DocumentNode *docNode=NULL;
printf("_word = 0x%X\n", (int)_word);
printf("*_word = %s\n\n", _word);
docNode=(DocumentNode *)malloc(sizeof(DocumentNode));
printf("_word = 0x%X\n", _word);
printf("_word[0] = %c\n\n", _word[0]);
docNode->next=NULL;
docNode->document_id=documentID;
docNode->page_word_frequency=1;
}
}
int main()
{
update_Index(0 , "inputWord");
char *tmp1, *tmp2;
tmp1 = (char*)malloc(10);
printf("tmp1 = 0x%X\n", tmp1);
tmp2 = (char*)malloc(10);
printf("tmp2 = 0x%X\n", tmp2);
}
Result:
_word = 0x40305F
*_word = inputWord
_word = 0x40305F
_word[0] = i
tmp1 = 0x9F3D48
tmp2 = 0x9F3D60
Process returned 0 (0x0) execution time : 0.054 s
Press any key to continue.