Skip to content

Commit 139637c

Browse files
author
Daniel Kroening
committed
multi_ary_exprt::opX with precondtion
This prevents out-of-bound accesses to operands().
1 parent 6c14669 commit 139637c

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/util/std_expr.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,56 @@ class multi_ary_exprt:public exprt
974974
{
975975
add_to_operands(_lhs, _rhs);
976976
}
977+
978+
// In contrast to exprt::opX, the methods
979+
// below check the size.
980+
exprt &op0()
981+
{
982+
PRECONDITION(operands().size() >= 1);
983+
return operands().front();
984+
}
985+
986+
exprt &op1()
987+
{
988+
PRECONDITION(operands().size() >= 2);
989+
return operands()[1];
990+
}
991+
992+
exprt &op2()
993+
{
994+
PRECONDITION(operands().size() >= 3);
995+
return operands()[2];
996+
}
997+
998+
exprt &op3()
999+
{
1000+
PRECONDITION(operands().size() >= 4);
1001+
return operands()[3];
1002+
}
1003+
1004+
const exprt &op0() const
1005+
{
1006+
PRECONDITION(operands().size() >= 1);
1007+
return operands().front();
1008+
}
1009+
1010+
const exprt &op1() const
1011+
{
1012+
PRECONDITION(operands().size() >= 2);
1013+
return operands()[1];
1014+
}
1015+
1016+
const exprt &op2() const
1017+
{
1018+
PRECONDITION(operands().size() >= 3);
1019+
return operands()[2];
1020+
}
1021+
1022+
const exprt &op3() const
1023+
{
1024+
PRECONDITION(operands().size() >= 4);
1025+
return operands()[3];
1026+
}
9771027
};
9781028

9791029
/// \brief Cast an exprt to a \ref multi_ary_exprt

0 commit comments

Comments
 (0)