From baea8cf9fab4d922a0759507b6f570bdeb8374ef Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 25 Dec 2020 09:13:46 +0100 Subject: [PATCH] glr2.cc: provide glr_state with a genuine copy-constructor 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 ()