[PATCH 4/5] glr2.cc: fix container out-of-bounds access

Akim Demaille <[email protected]>
Newsgroups gmane.comp.parsers.bison.patches
Message-ID <[email protected]>
From: Valentin Tolmer <[email protected]>

Clang 10 with ASAN enabled reported errors in glr2.cc.

* data/skeletons/glr2.cc: here.
---
 data/skeletons/glr2.cc | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc
index 343489ab..b2dd6f23 100644
--- a/data/skeletons/glr2.cc
+++ b/data/skeletons/glr2.cc
@@ -2273,12 +2273,13 @@ public:
       {
         /* Standard special case: single stack.  */
         YYASSERT (yyk.get() == 0);
-        glr_stack_item* yyrhs = yystateStack.topAt(yyk)->asItem();
-        yystateStack.pop_back(static_cast<size_t>(yynrhs));
-        yystateStack.setFirstTop(&yystateStack[yystateStack.size() - 1].getState());
+        glr_stack_item* yyrhs = yystateStack.firstTop()->asItem();
         YY_REDUCE_PRINT ((true, yyrhs, yyk, yyrule, yyparser]b4_user_args[));
-        return yyuserAction (yyrule, yynrhs, yyrhs,
+        YYRESULTTAG res =  yyuserAction (yyrule, yynrhs, yyrhs,
                              yyvalp]b4_locations_if([, yylocp])[);
+        yystateStack.pop_back(static_cast<size_t>(yynrhs));
+        yystateStack.setFirstTop(&yystateStack[yystateStack.size() - 1].getState());
+        return res;
       }
     else
       {
-- 
2.28.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.