0

So I am writing a ternary tree and I get seg faults after maybe 20 insertions. When I isolate the problem in GDB I get a very odd error I have never seen before.

on the statement of code below, greater is another NODE and that node SHOULD be NULL (or another node) but when I am in GDB and I check its value I get *tempNode->0x4 this causes my code to attempt to set greater (0x4) as current node and results in a seg fault.

 if( ! tempNode->greater )


 else
 {
 tempNode = tempNode->greater;
 }

Here is the GDB output: (gdb) p *tempNode->greater Cannot access memory at address 0x4

been stuck for hours, any ideas?

Elblonko
  • 25
  • 4
  • Is tempnode a local variable? Looks like it's filled with garbage - you can initialize it to zeroes at function start. Examine how tempNode gets assigned (does it get assigned for every path through your function, or is it used uninitialized for any path?). – Brenda J. Butler Mar 10 '14 at 05:53
  • I think the problem is at somewhere else, either as @BrendaJ.Butler said the initialization, or when inserting or modifying the tree some pointer did not be set NULL. – Cigany Mar 10 '14 at 06:02
  • You sir are my savior, I think I have been working on this too long. I figured since it was a reproducible error always with the same value it couldn't be garbage.... wrong....THANKS! – Elblonko Mar 10 '14 at 06:04

0 Answers0