From 18d9185cae4c43684e4a2a134dd3090b55307586 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Mon, 27 Feb 2006 19:50:59 +0000
Subject: [PATCH] * data/glr.c (yyexpandGLRStack): Catch an off-by-one error
 that led to a segmentation fault in GNU Pascal.  Problem reported by Waldek
 Hebisch.

---
 ChangeLog  | 6 ++++++
 data/glr.c | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index d56eb26e..8a12134a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-02-27  Paul Eggert  <eggert@cs.ucla.edu>
+
+	* data/glr.c (yyexpandGLRStack): Catch an off-by-one error that
+	led to a segmentation fault in GNU Pascal.  Problem reported
+	by Waldek Hebisch.
+
 2006-02-21  Joel E. Denny  <jdenny@ces.clemson.edu>
 
 	* doc/bison.texinfo (Mid-Rule Actions): Explain how to bury a
diff --git a/data/glr.c b/data/glr.c
index 3430f1bb..48eae8d5 100644
--- a/data/glr.c
+++ b/data/glr.c
@@ -1190,7 +1190,7 @@ yyexpandGLRStack (yyGLRStack* yystackp)
   size_t yysize, yynewSize;
   size_t yyn;
   yysize = yystackp->yynextFree - yystackp->yyitems;
-  if (YYMAXDEPTH <= yysize)
+  if (YYMAXDEPTH - YYHEADROOM < yysize)
     yyMemoryExhausted (yystackp);
   yynewSize = 2*yysize;
   if (YYMAXDEPTH < yynewSize)
-- 
2.47.2