Crash when clearing "ans" variable in symbol table

John W. Eaton jwe at bevo.che.wisc.edu
Mon Jan 14 15:54:32 CST 2008


On 14-Jan-2008, Michael Goffioul wrote:

| On 1/14/08, John W. Eaton <jwe at bevo.che.wisc.edu> wrote:
| > Objects are pushed on the value_stack when functions are called
| > recursively.  My guess is that you've found some way to have a
| > recursive call that doesn't properly trigger the push, but still has a
| > pop of the stack.
| 
| Will you have a look into this? Or could you give me some hints
| where to look (I currently have no clue).
| [Note that this is not my code; I just found the problem while testing
| someone else's code; I have no more clues about the offending code]

Please try the following patch.

I think the problem is that "ans" is being added to the symbol table
in a recursive call, so the size of its value_stack is not equal to
the depth of the recursion.  The following patch addresses this by
removing symbols from the table when their value_stack becomes empty.

I think a simple test case is

  function foo (n)
    if (n > 0)
      n
      ans_exists = exist ("ans", "var")  # should be 0.
      foo (n-1);
      ans_exists = exist ("ans", "var")  # should be 0.
    else
      ans_exists = exist ("ans", "var")  # should be 0.
      eval ("13;");
      ans_exists = exist ("ans", "var")  # should be 1.
    endif
  endfunction

Try running this with something like

  foo (3)

With the patch it should only have ans in the deepest of the
recursive calls to foo.  Without it, Octave should crash.

Hey Sergei, here is a chance for you to help us out by creating some
tests.

Thanks,

jwe


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: diffs
Url: https://www.cae.wisc.edu/pipermail/octave-maintainers/attachments/20080114/99fd2e53/attachment.ksh 


More information about the Octave-maintainers mailing list