Skip to content

Commit

Permalink
Throw an error instead of assert-crashing on eval stack underflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
kilobyte committed Aug 31, 2023
1 parent ac3f094 commit 685e18b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
7 changes: 4 additions & 3 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,10 @@ static bool do_one_inside(int begin, int end)
}
else
{
int next;
assert(loc >= 0);
next = stacks[loc].pos;
if (loc < 0)
return false;

int next = stacks[loc].pos;
if (ploc == -1 || stacks[next].pos == 0 || stacks[next].prio != PRIO_LITERAL)
return false;
if (stacks[ploc].prio != PRIO_LITERAL)
Expand Down
4 changes: 4 additions & 0 deletions tests/data/badmath.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#math x ()
#math x 1/
#math x 1/0
#math x ))
4 changes: 4 additions & 0 deletions tests/data/badmath.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#Invalid expression to evaluate in {()}
#Invalid expression to evaluate in {1/}
#Error: Division by zero.
#Unmatched parentheses error in {))}.

0 comments on commit 685e18b

Please sign in to comment.