bison-patches
[Top][All Lists]
Advanced

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

[PATCH 3/6] glr2.cc: provide glr_state with a genuine copy-constructor


From: Akim Demaille
Subject: [PATCH 3/6] glr2.cc: provide glr_state with a genuine copy-constructor
Date: Sat, 26 Dec 2020 08:11:37 +0100

The copy constructor was (lazily) implemented by a call to copyFrom.
Unfortunately copyFrom reads yyresolved from the destination (and
source), and in the case of the copy-ctor this is random garbagge,
which UBSAN catches:

    glr-regr2a.cc:1072:10: runtime error: load of value 7, which is not a valid 
value for type 'bool'

Rather than defining yyresolved before calling copyFrom, let's just
provide a genuine cpy-ctor for glr_state.

* data/skeletons/glr2.cc (glr_state::glr_state): Implement properly.
---
 data/skeletons/glr2.cc | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc
index e76a376a..534fe8c4 100644
--- a/data/skeletons/glr2.cc
+++ b/data/skeletons/glr2.cc
@@ -802,11 +802,20 @@ public:
     , magic_ (MAGIC)]])[
   {}
 
-  glr_state (const glr_state& other)]b4_parse_assert_if([[
-    : magic_ (MAGIC)]])[
+  glr_state (const glr_state& other)
+    : yyresolved (other.yyresolved)
+    , yylrState (other.yylrState)
+    , yyposn (other.yyposn)
+    , yypred (0)]b4_locations_if([[
+    , yyloc (other.yyloc)]])[]b4_parse_assert_if([[
+    , magic_ (MAGIC)]])[
   {
-    // FIXME: Do it right.
-    copyFrom (other);
+    setPred (other.pred ());
+    if (other.yyresolved)
+      new (&yysval) value_type (other.semanticVal ());
+    else
+      setFirstVal (other.firstVal ());]b4_parse_assert_if([[
+    check_();]])[
   }
 
   ~glr_state ()
-- 
2.29.2




reply via email to

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