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.
This commit is contained in:
Akim Demaille
2020-12-25 09:13:46 +01:00
parent 636c9a8042
commit baea8cf9fa

View File

@@ -802,11 +802,20 @@ public:
, magic_ (MAGIC)]])[ , magic_ (MAGIC)]])[
{} {}
glr_state (const glr_state& other)]b4_parse_assert_if([[ glr_state (const glr_state& other)
: magic_ (MAGIC)]])[ : 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. setPred (other.pred ());
copyFrom (other); if (other.yyresolved)
new (&yysval) value_type (other.semanticVal ());
else
setFirstVal (other.firstVal ());]b4_parse_assert_if([[
check_();]])[
} }
~glr_state () ~glr_state ()