File tree Expand file tree Collapse file tree 3 files changed +30
-3
lines changed
regression/ansi-c/Union_Initialization2 Expand file tree Collapse file tree 3 files changed +30
-3
lines changed Original file line number Diff line number Diff line change 1+ union a {
2+ } b ()
3+ {
4+ union a c = {0 };
5+ }
Original file line number Diff line number Diff line change 1+ CORE
2+ main.c
3+
4+ union member designator found for empty union
5+ ^SIGNAL=0$
6+ ^EXIT=(1|64)$
7+ --
8+ member designator is bounded by components size
9+ --
10+ This test previously failed an internal invariant, which is not the correct
11+ behaviour the problem can be triggered by user input.
Original file line number Diff line number Diff line change @@ -478,10 +478,21 @@ exprt::operandst::const_iterator c_typecheck_baset::do_designated_initializer(
478478 const union_typet::componentst &components=
479479 union_type.components ();
480480
481- DATA_INVARIANT (index<components.size (),
482- " member designator is bounded by components size" );
481+ if (components.empty ())
482+ {
483+ error ().source_location = value.source_location ();
484+ error () << " union member designator found for empty union" << eom;
485+ throw 0 ;
486+ }
487+ else if (index >= components.size ())
488+ {
489+ error ().source_location = value.source_location ();
490+ error () << " union member designator " << index << " out of bounds ("
491+ << components.size () << " )" << eom;
492+ throw 0 ;
493+ }
483494
484- const union_typet::componentt &component=union_type. components () [index];
495+ const union_typet::componentt &component = components[index];
485496
486497 if (dest->id ()==ID_union &&
487498 dest->get (ID_component_name)==component.get_name ())
You can’t perform that action at this time.
0 commit comments