@@ -417,7 +417,7 @@ void interpretert::execute_decl()
417
417
418
418
// / retrieves the member at offset
419
419
// / \par parameters: an object and a memory offset
420
- irep_idt interpretert::get_component_id (
420
+ struct_typet::componentt interpretert::get_component (
421
421
const irep_idt &object,
422
422
unsigned offset)
423
423
{
@@ -428,15 +428,16 @@ irep_idt interpretert::get_component_id(
428
428
429
429
const struct_typet &struct_type=to_struct_type (real_type);
430
430
const struct_typet::componentst &components=struct_type.components ();
431
- for (struct_typet::componentst::const_iterator it=components. begin ();
432
- it!= components. end (); it++ )
431
+
432
+ for ( const auto &c : components)
433
433
{
434
434
if (offset<=0 )
435
- return it-> id () ;
436
- size_t size= get_size (it-> type ());
437
- offset-=size ;
435
+ return c ;
436
+
437
+ offset-=get_size (c. type ()) ;
438
438
}
439
- return object;
439
+
440
+ throw " access out of struct bounds" ;
440
441
}
441
442
442
443
// / returns the type object corresponding to id
@@ -600,6 +601,7 @@ exprt interpretert::get_value(
600
601
result.set_value (ID_NULL);
601
602
return result;
602
603
}
604
+
603
605
if (rhs[offset]<memory.size ())
604
606
{
605
607
// We want the symbol pointed to
@@ -612,15 +614,18 @@ exprt interpretert::get_value(
612
614
613
615
if (offset==0 )
614
616
return address_of_exprt (symbol_expr);
617
+
615
618
if (ns.follow (type).id ()==ID_struct)
616
619
{
617
- irep_idt member_id= get_component_id (identifier, offset);
618
- member_exprt member_expr (symbol_expr, member_id );
620
+ const auto c= get_component (identifier, offset);
621
+ member_exprt member_expr (symbol_expr, c );
619
622
return address_of_exprt (member_expr);
620
623
}
624
+
621
625
index_exprt index_expr (
622
626
symbol_expr,
623
627
from_integer (offset, integer_typet ()));
628
+
624
629
return index_expr;
625
630
}
626
631
0 commit comments