bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: %destructor and stack overflow


From: Paul Eggert
Subject: Re: %destructor and stack overflow
Date: Sun, 01 May 2005 06:28:46 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux)

Thanks for the patch, but I suspect the code patch isn't quite general
enough, since a similar problem occurs if the user invokes YYACCEPT or
YYABORT.  How about this patch instead?

2005-05-01  Paul Eggert  <address@hidden>

        * data/yacc.c (yyerrlab): Move the code that destroys the stack
        from here....
        (yyreturn): to here.  That way, destructors are called properly
        even if the stack overflows, or the user calls YYACCEPT or
        YYABORT.  Stack-overflow problem reported by Marcus Holland-Moritz.
        (yyoverflowlab): Destroy the lookahead.

--- yacc.c.~1.86.~      2005-04-24 20:13:06 -0700
+++ yacc.c      2005-05-01 06:12:32 -0700
@@ -1203,15 +1203,7 @@ yyerrlab:
           /* If at end of input, pop the error token,
             then the rest of the stack, then return failure.  */
          if (yychar == YYEOF)
-            for (;;)
-              {
-]b4_location_if([[                 yyerror_range[0] = *yylsp;]])[
-                YYPOPSTACK;
-                if (yyssp == yyss)
-                  YYABORT;
-                yydestruct (_("Error: popping"),
-                             yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[);
-              }
+           YYABORT;
         }
       else
        {
@@ -1316,11 +1308,23 @@ yyabortlab:
 `----------------------------------------------*/
 yyoverflowlab:
   yyerror (]b4_yyerror_args[_("parser stack overflow"));
+  yydestruct (_("Error: discarding lookahead"),
+             yytoken, &yylval]b4_location_if([, &yylloc])[);
   yyresult = 2;
   /* Fall through.  */
 #endif
 
 yyreturn:
+  if (yyssp != yyss)
+    for (;;)
+      {
+]b4_location_if([[     yyerror_range[0] = *yylsp;]])[
+       YYPOPSTACK;
+       if (yyssp == yyss)
+         break;
+       yydestruct (_("Error: popping"),
+                   yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[);
+      }
 #ifndef yyoverflow
   if (yyss != yyssa)
     YYSTACK_FREE (yyss);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]