Skip to content

Commit

Permalink
bc: runtime error eats too much input
Browse files Browse the repository at this point in the history
* In interactive bc, calling an undefined function does not cause a fatal error but an error is printed
* YYERROR() is called in this situation, but it seems to break something
* It appears that input tokens past the end of current statement are eaten by YYERROR
* I observed this:

ME> x = hey(1) + 2
BC> No function hey() has been defined
ME> x
ME> x
BC> 0
ME> quit

* After the error bc ignores the first time I type x (but when I ask again it politely answers)
* Replacing YYERROR with "last INSTR" causes bc to jump past the final instruction in the current statement
* Instructions in the subsequent statement are not destroyed
* With this patch, the statement after the error is executed as I expect (this matches GNU bc)

ME> x = 5
BC> 5
ME> y = heh(6) + 7
BC> No function heh() has been defined
ME> x
BC> 5
ME> y
BC> 0
ME> quit
  • Loading branch information
mknos authored Oct 14, 2023
1 parent a16ab0a commit 6cf6f82
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion bin/bc
Original file line number Diff line number Diff line change
Expand Up @@ -2611,7 +2611,7 @@ sub exec_stmt
print STDERR "No function $name has been defined\n";
@ope_stack = (0);
$return = 3;
YYERROR;
last INSTR;
}

if($sym_table{$name}{type} eq 'builtin') {
Expand Down

0 comments on commit 6cf6f82

Please sign in to comment.