From 6fdb09caac6ee472315f0cf849cb2e105d931266 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Wed, 20 Jul 2005 21:43:32 +0000
Subject: [PATCH] (yyreturn): Don't pop stack if yyinitStateSet failed, as the
 stack isn't valid in that case.

---
 data/glr.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/data/glr.c b/data/glr.c
index 578ad116..219dd3f5 100644
--- a/data/glr.c
+++ b/data/glr.c
@@ -2107,17 +2107,21 @@ b4_syncline([@oline@], [@ofile@])])dnl
                 yytoken, yylvalp]b4_location_if([, yyllocp])[);
 
   /* Now pop stack until empty, destroying its entries as we go.  */
-  while (yystack.yytops.yystates[0] != NULL)
-    {
-      yyGLRState *yys = yystack.yytops.yystates[0];
-]b4_location_if([[      yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]])[
-      yydestruct ("Error: popping",
-		  yystos[yys->yylrState],
-		  &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
-      yystack.yytops.yystates[0] = yys->yypred;
-      yystack.yynextFree -= 1;
-      yystack.yyspaceLeft += 1;
-    }
+  {
+    yyGLRState** yystates = yystack.yytops.yystates;
+    if (yystates)
+      while (yystates[0])
+	{
+	  yyGLRState *yys = yystates[0];
+]b4_location_if([[	  yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]]
+)[	  yydestruct ("Error: popping",
+		      yystos[yys->yylrState],
+		      &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
+	  yystates[0] = yys->yypred;
+	  yystack.yynextFree -= 1;
+	  yystack.yyspaceLeft += 1;
+	}
+  }
 
   yyfreeGLRStack (&yystack);
   return yyresult;
-- 
2.47.2