Menu

#334 looping crash

v1.0_(example)
open
nobody
None
5
5 days ago
6 days ago
No

Example:

# strings mystrs = defarray("y$i") # yields only strange error message

strings mystrs = defarray("y$iy")

loop foreach i mystrs # i "needs" to match the input here to provoke it
    print "$i"
endloop 

This is about substitute_dollar_targ() in monte_carlo.c. Some of the relevant lines are surely the copies:

    strcpy(q, p + targlen);
    strcpy(p, ins);
    strcpy(p + inslen, q);

I'm also noting the existing comment / += strlen(ins)? / (instead of s++), but I don't know if that would be or contribute to the solution.

Discussion

  • Allin Cottrell

    Allin Cottrell - 5 days ago

    This is now fixed in git, in the sense that given a "foreach" loop over an array of strings, we check the strings and flag an error if any of them contain "$ivar", where ivar is the index variable. So, no crash but an error if this sort of recursion is detected.

     
    • Sven Schreiber

      Sven Schreiber - 5 days ago

      Am 05.09.2026 um 14:35 schrieb Allin Cottrell:

      This is now fixed in git, in the sense that given a "foreach" loop over an array of strings, we check the strings and flag an error if any of them contain "$ivar", where ivar is the index variable. So, no crash but an error if this sort of recursion is detected.
      Thanks - I think this is a good solution (so can be closed). -sven

       

Log in to post a comment.