bison-patches
[Top][All Lists]
Advanced

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

glr2.cc: fix calling conventions for yyexpandGLRStackIfNeeded


From: Akim Demaille
Subject: glr2.cc: fix calling conventions for yyexpandGLRStackIfNeeded
Date: Sun, 20 Dec 2020 08:34:36 +0100

commit 073d52147617ff5c09bf93e5f88afd047fc5b225
Author: Akim Demaille <akim.demaille@gmail.com>
Date:   Sat Dec 19 18:38:08 2020 +0100

    glr2.cc: fix calling conventions for yyexpandGLRStackIfNeeded
    
    This test fails:
    
    748: Incorrect lookahead during nondeterministic GLR: glr2.cc
    
    It consumes lots of stack space, so at some point we need to expand
    it.  Because of Boolean logic mistakes, we then claim
    memory-exhausted (first error).  Hence we jump to cleaning the
    stack (popall_), calling all the destructors, and at some point we
    crash with heap-use-after-free (second error).
    
    This commit fixes the first error.  Unfortunately, even though we now
    do expand the stack, we crash again with (another)
    heap-use-after-free, not addressed here.
    
    Eventually, we should make sure popall_() properly works.
    
    * data/skeletons/glr2.cc (yyexpandGLRStackIfNeeded): Return true iff
    success (i.e., memory not exhausted).

diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc
index 038b80f5..8a28b68e 100644
--- a/data/skeletons/glr2.cc
+++ b/data/skeletons/glr2.cc
@@ -1443,7 +1443,7 @@ class state_stack {
   /** Returns false if it tried to expand but could not. */
   bool
   yyexpandGLRStackIfNeeded() {
-    return spaceLeft() < YYHEADROOM && yyexpandGLRStack();
+    return YYHEADROOM <= spaceLeft() || yyexpandGLRStack();
   }
 
  private:
@@ -1465,7 +1465,7 @@ class state_stack {
 #else
   bool yyexpandGLRStackIfNeeded ()
   {
-    return spaceLeft () < YYHEADROOM;
+    return YYHEADROOM <= spaceLeft ();
   }
 #endif
 
@@ -1889,7 +1889,7 @@ public:
   ]b4_namespace_ref[::]b4_parser_class[& yyparser;
 
   void yyreserveGlrStack() {
-    if (yystateStack.yyexpandGLRStackIfNeeded ())
+    if (!yystateStack.yyexpandGLRStackIfNeeded ())
       yyMemoryExhausted();
   }
 




reply via email to

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