While trying to implement the size function in pest5, I noticed I was seg faulting and traced it back to an error in the load function. It appears that after the first letter is read into the trie, the subsequent nodes appear to have pointers to the value 0x11
. It is not every node in the trie and I can't find a pattern to it. I'll place the relevant code below. It appears to happen around the new malloc()
call.
for (int c = fgetc(dict); c != EOF; c = fgetc(dict))
{
int index = 0;
if (c == '\n')
{
if (node != root)
{
//set word to true
node->is_word = true;
node = root;
}
}
else
{
index = alpha_index(c);
if (node->children[index] != NULL)
{
//break loop if pointer already exists
node = node->children[index];
}
else
{
//point to new node
tmp = node;
node->children[index] = malloc(sizeof(node));
node = node->children[index];
node->parent = tmp;
}
}
typedef struct node { bool is_word; struct node* children[27]; struct node* parent; } node;
tmp
is simply anode*
node.parent
seems to work correctly as doesnode.is_true
, it is just the children that seem to be adding in odd values.parent
member?