Results 1 to 3 of 3
Hi guys,
I have a baffling problem!! Or at least it seems that way. Basically I've been making a pangolins program which uses a set of nodes in a yes ...
- 07-16-2010 #1Just Joined!
- Join Date
- Feb 2009
- Location
- Southport, England
- Posts
- 31
Different value passed into method (solved)
Hi guys,
I have a baffling problem!! Or at least it seems that way. Basically I've been making a pangolins program which uses a set of nodes in a yes or no path tree structure and traverses the tree according to questions asked to the user, and inserts appropriate new questions and answer guesses.
I get a segfault which (seems to be) arbitrary. I use node pointer types (node_t*) which have a linked list way of linking to each other: each node_t has 2 recursive node_t* types like so:
and an enum titleDepth which tells me whether I got here by a yes or no path. I am recursively calling a method:Code:typedef struct node_t { char* label; char* question; struct node_t* yes; struct node_t* no; } node_t;
within which I get to the point where I'm calling it in one of 2 variations:Code:node_t* interact(node_t* node, node_t* previousNode, titleDepth whereFrom)
I have a backtrace:Code:if (response == 'y' || response == 'Y') return interact(node->yes, node, yes); // Line 137 else return interact(node->no, node, no); // Line 139
I have used gdb to go to frame 1 and print out the value of node->no:Code:#0 0x0000000000400aaa in interact (node=Cannot access memory at address 0x7fffff3fdbf8 ) at part2.c:115 #1 0x0000000000400bf1 in interact (node=0x602840, prev=0x6027a0, path=no) at part2.c:139 #2 0x0000000000400bf1 in interact (node=0x6027a0, prev=0x602290, path=no) at part2.c:139 #3 0x0000000000400bf1 in interact (node=0x602290, prev=0x602150, path=yes) at part2.c:139 #4 0x0000000000400bca in interact (node=0x602150, prev=0x602010, path=no) at part2.c:137 #5 0x0000000000400bf1 in interact (node=0x602010, prev=0x0, path=yes) at part2.c:139 #6 0x000000000040143d in main (argc=2, argv=0x7fffffffdf28) at part2.c:427
So, the way I see it is, I'm passing 0x602750 into the first argument of the method and what comes out in the new method is 0x7fffff3fdbf8 !? By the way, line 115 is the '{' brace after the method name.Code:(gdb) frame 1 #1 0x0000000000400bf1 in interact (node=0x602840, prev=0x6027a0, path=no) at part2.c:139 139 return interact(node->no, node, no); (gdb) p node->no $15 = (struct node_t *) 0x602750
God, I hope I'm not being really naive! Please help!
Thanks
- 07-16-2010 #2Just Joined!
- Join Date
- Feb 2009
- Location
- Southport, England
- Posts
- 31
Actually, it seems to be occurring after a depth of 5 recursive calls, except now it's happened at a different line number, where I am calling a different method (which prints out the tree from the node node, which works at all other times).
EDIT: I'm pretty confident it is always when I have 7 frames (#0-6) and then I make another method call, whether recursive or not.
Again, baffling. I'm beginning to think this is some kind of security limit; possibly something to do with stack space? Has anyone come across this before?
Thanks!
- 07-16-2010 #3Just Joined!
- Join Date
- Feb 2009
- Location
- Southport, England
- Posts
- 31
Yes, sorry, I've solved it: it was stack space. Used ulimit -s 1048576 and now I can go beyond where I could before.


Reply With Quote
