Skip to content

Commit 2f995d6

Browse files
committed
DoList: Fix bug causing malformed lists to be generated
While evaluating the program for `DoList` or `DoSub`, the scratch pad could be expanded by the program, adding "junk" to the generated list. Added code that restores the scratchpad after program evaluation if necessary. This bug was detected by the GitHub CI on Windows where it was causing an assertion failure on the generated list. Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
1 parent 35cef61 commit 2f995d6

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/list.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,7 +2438,11 @@ COMMAND_BODY(DoList)
24382438
return ERROR;
24392439
}
24402440

2441+
size_t scratch = rt.allocated();
24412442
program::run(prg, true);
2443+
size_t scratch_used = rt.allocated();
2444+
if (scratch_used > scratch)
2445+
rt.free(scratch_used - scratch);
24422446

24432447
size_t after = rt.depth();
24442448
if (after < depth)
@@ -2530,7 +2534,11 @@ COMMAND_BODY(DoSubs)
25302534
if (!rt.push(lst->at(i + d)))
25312535
return ERROR;
25322536

2537+
size_t scratch = rt.allocated();
25332538
program::run(prg, true);
2539+
size_t scratch_used = rt.allocated();
2540+
if (scratch_used > scratch)
2541+
rt.free(scratch_used - scratch);
25342542

25352543
size_t after = rt.depth();
25362544
if (after < depth)

0 commit comments

Comments
 (0)