Skip to content

Commit 2d03d27

Browse files
committed
Pointer arithmetic overflow is overflow on integer representation
At a bare minimum, we should report an overflow when performing pointer arithmetic that would result in an overflow on the underlying integer representation. As future work, we may want to expand on those checks by reporting overflows when exceeding object bounds, as discussed in diffblue#5426. Fixes: diffblue#5284
1 parent b902e0b commit 2d03d27

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

regression/cbmc/pointer-overflow2/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33
--pointer-overflow-check
44
^EXIT=0$

src/analyses/goto_check.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,8 +1157,13 @@ void goto_checkt::pointer_overflow_check(
11571157
expr.operands().size() == 2,
11581158
"pointer arithmetic expected to have exactly 2 operands");
11591159

1160+
// check for address space overflow by checking for overflow on integers
11601161
exprt overflow("overflow-" + expr.id_string(), bool_typet());
1161-
overflow.operands() = expr.operands();
1162+
for(const auto &op : expr.operands())
1163+
{
1164+
overflow.add_to_operands(
1165+
typecast_exprt::conditional_cast(op, pointer_diff_type()));
1166+
}
11621167

11631168
add_guarded_property(
11641169
not_exprt(overflow),

0 commit comments

Comments
 (0)