@@ -417,7 +417,7 @@ void interpretert::execute_decl()
417417
418418// / retrieves the member at offset
419419// / \par parameters: an object and a memory offset
420- irep_idt interpretert::get_component_id (
420+ struct_typet::componentt interpretert::get_component (
421421 const irep_idt &object,
422422 unsigned offset)
423423{
@@ -428,15 +428,16 @@ irep_idt interpretert::get_component_id(
428428
429429 const struct_typet &struct_type=to_struct_type (real_type);
430430 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)
433433 {
434434 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 ()) ;
438438 }
439- return object;
439+
440+ throw " access out of struct bounds" ;
440441}
441442
442443// / returns the type object corresponding to id
@@ -600,6 +601,7 @@ exprt interpretert::get_value(
600601 result.set_value (ID_NULL);
601602 return result;
602603 }
604+
603605 if (rhs[offset]<memory.size ())
604606 {
605607 // We want the symbol pointed to
@@ -612,15 +614,18 @@ exprt interpretert::get_value(
612614
613615 if (offset==0 )
614616 return address_of_exprt (symbol_expr);
617+
615618 if (ns.follow (type).id ()==ID_struct)
616619 {
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 );
619622 return address_of_exprt (member_expr);
620623 }
624+
621625 index_exprt index_expr (
622626 symbol_expr,
623627 from_integer (offset, integer_typet ()));
628+
624629 return index_expr;
625630 }
626631
0 commit comments