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).
This commit is contained in:
Akim Demaille
2020-12-19 18:38:08 +01:00
parent 7292ed6e64
commit 08f657f4a4

View File

@@ -1449,7 +1449,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:
@@ -1471,7 +1471,7 @@ class state_stack {
#else
bool yyexpandGLRStackIfNeeded ()
{
return spaceLeft () < YYHEADROOM;
return YYHEADROOM <= spaceLeft ();
}
#endif
@@ -1895,7 +1895,7 @@ public:
]b4_namespace_ref[::]b4_parser_class[& yyparser;
void yyreserveGlrStack() {
if (yystateStack.yyexpandGLRStackIfNeeded ())
if (!yystateStack.yyexpandGLRStackIfNeeded ())
yyMemoryExhausted();
}