[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
- [PATCH 0/6] glr2.cc: more fixes, Akim Demaille, 2020/12/26
- [PATCH 1/6] glr: comment changes, Akim Demaille, 2020/12/26
- [PATCH 2/6] glr2.cc: beware of self-assignment, Akim Demaille, 2020/12/26
- [PATCH 3/6] glr2.cc: provide glr_state with a genuine copy-constructor,
Akim Demaille <=
- [PATCH 4/6] glr2.cc: fix warnings about uninitialized locations, Akim Demaille, 2020/12/26
- [PATCH 5/6] glr2.cc: simplify, Akim Demaille, 2020/12/26
- [PATCH 6/6] doc: more about sanitizers, Akim Demaille, 2020/12/26