Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bc: yyparse() loop regression #619

Merged
merged 1 commit into from
May 24, 2024
Merged

Conversation

mknos
Copy link
Contributor

@mknos mknos commented May 24, 2024

  • A previous commit replaced a goto into yyparse() with a call to yyparse() but this introduced an infinite loop for a file with a syntax error
  • yy_err_recover() returns bool; returning 1 instead of calling yyparse() again allows yyparse() to itself return and break out of "yyloop"
  • The pattern of return(1) from yy_err_recover() was already established; this patch just makes it more consistent
  • Regarding the removed yyclearin() call, that would be called from main()->clear_flags() before yyparse() would be called again
  • test1: echo '1++' > A.bc && perl bc -y A.bc
  • test2: echo '~' > B.bc && perl bc -y B.bc
%echo '1++' > A.bc && perl bc -y A.bc   # before patch
yydebug: state 1, reading 0 (end-of-file)
yydebug: state 1, reducing by rule 2 (stmt_list_exec : stmt_list_exec stmt_exec)
yydebug: after reduction, shifting from state 0 to state 1
yydebug: state 1, error recovery shifting to state 2
"A.bc", line 1: syntax error
yydebug: error recovery discarding state 2
yydebug: state 1, error recovery shifting to state 2
yydebug: error recovery discarding state 2
yydebug: state 1, error recovery shifting to state 2
yydebug: error recovery discarding state 2
yydebug: state 1, error recovery shifting to state 2
yydebug: error recovery discarding state 2
LOOP

* A previous commit replaced a goto into yyparse() with a call to yyparse() but this introduced an infinite loop for a file with a syntax error
* yy_err_recover() returns bool; returning 1 instead of calling yyparse() again allows yyparse() to itself return and break out of "yyloop"
* The pattern of return(1) from yy_err_recover() was already established; this patch just makes it more consistent
* test1: echo '1++' > A.bc && perl bc -y A.bc
* test2: echo '~' > B.bc && perl  bc -y B.bc
@github-actions github-actions bot added Type: enhancement improve a feature that already exists Priority: low get to this whenever Program: bc The bc program labels May 24, 2024
@briandfoy briandfoy merged commit 1c83543 into briandfoy:master May 24, 2024
2 checks passed
@briandfoy briandfoy added Type: bug an existing feature does not work and removed Type: enhancement improve a feature that already exists labels May 24, 2024
@briandfoy briandfoy added Status: accepted The fix is accepted and removed Priority: low get to this whenever labels May 24, 2024
@briandfoy briandfoy self-assigned this May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Program: bc The bc program Status: accepted The fix is accepted Type: bug an existing feature does not work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants