Find the answer to your Linux question:
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 ...
  1. #1
    Just 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:

    Code:
    typedef struct node_t
    {
    	char* label;
    	char* question;
    	struct node_t* yes;
    	struct node_t* no;
    } node_t;
    and an enum titleDepth which tells me whether I got here by a yes or no path. I am recursively calling a method:

    Code:
    node_t* interact(node_t* node, node_t* previousNode, titleDepth whereFrom)
    within which I get to the point where I'm calling it in one of 2 variations:

    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 a backtrace:

    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
    I have used gdb to go to frame 1 and print out the value of node->no:

    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
    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.

    God, I hope I'm not being really naive! Please help!

    Thanks

  2. #2
    Just Joined!
    Join Date
    Feb 2009
    Location
    Southport, England
    Posts
    31
    Quote Originally Posted by lemons View Post
    I get a segfault which (seems to be) arbitrary...
    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!

  3. #3
    Just 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...