Skip to content

Commit 64c2c3d

Browse files
authored
bc: eliminate jump into yyparse()
* When temporarily enabling warnings in bc I observe warnings for incorrect use of "next" * Function yy_err_recover() jumped to a label outside of itself, within yyparse() * yyparse() was strucured so that it first initialises flags then enters main loop * Jumping back to yyparse() was unsafe because the flags would all be cleared again, including $yyssp (yy_err_recover() already adjusts $yyssp) * Clear flags before calling yyparse(), and let yyparse() enter the loop immediately so that it's safe to call it from yy_err_recover() %perl bc # before patch 4++ line 1: syntax error Exiting subroutine via next at bc line 1387, <STDIN> line 1 (briandfoy#1)
1 parent c825726 commit 64c2c3d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

bin/bc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ sub yy_err_recover
13821382
" to state $yytable[$yyn]\n" if $yydebug;
13831383
$yyss[++$yyssp] = $yystate = $yytable[$yyn];
13841384
$yyvs[++$yyvsp] = $yylval;
1385-
next yyloop;
1385+
yyparse();
13861386
}
13871387
else
13881388
{
@@ -1406,16 +1406,19 @@ sub yy_err_recover
14061406
"token $yychar ($yys)\n";
14071407
}
14081408
yyclearin();
1409-
next yyloop;
1409+
yyparse();
14101410
}
14111411
0;
14121412
} # yy_err_recover
14131413

1414-
sub yyparse
1414+
sub clear_flags
14151415
{
14161416
yyclearin();
14171417
$yynerrs = $yyerrflag = $yyssp = $yyvsp = $yyss[0] = $yystate = 0;
1418+
}
14181419

1420+
sub yyparse
1421+
{
14191422
yyloop: while(1)
14201423
{
14211424
yyreduce: {
@@ -2749,6 +2752,7 @@ sub main
27492752
{
27502753
$line = '';
27512754
eval {
2755+
clear_flags();
27522756
$status = yyparse();
27532757
1;
27542758
} or do {

0 commit comments

Comments
 (0)