Skip to content

Commit 3921efc

Browse files
committed
Fixup Add invariant on component index being in range
1 parent 7e91b33 commit 3921efc

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/util/std_expr.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -1827,13 +1827,19 @@ class struct_exprt:public exprt
18271827
/// \return The expression for a named component of this struct.
18281828
exprt &component(const irep_idt &name)
18291829
{
1830-
return operands()[to_struct_type(type()).component_number(name)];
1830+
const auto index = to_struct_type(type()).component_number(name);
1831+
DATA_INVARIANT(
1832+
index < operands().size(), "component matching index should exist");
1833+
return operands()[index];
18311834
}
18321835

18331836
/// \return The expression for a named component of this struct.
18341837
const exprt &component(const irep_idt &name) const
18351838
{
1836-
return operands()[to_struct_type(type()).component_number(name)];
1839+
const auto index = to_struct_type(type()).component_number(name);
1840+
DATA_INVARIANT(
1841+
index < operands().size(), "component matching index should exist");
1842+
return operands()[index];
18371843
}
18381844
};
18391845

0 commit comments

Comments
 (0)