Skip to content

Commit a20fb34

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 f6ce727 commit a20fb34

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33
--pointer-overflow-check
44
^EXIT=0$
55
^SIGNAL=0$
6-
\[main.overflow.1\] line \d+ pointer arithmetic overflow on - in p - \(signed long int\)1: SUCCESS
7-
\[main.overflow.2\] line \d+ pointer arithmetic overflow on \+ in p \+ \(signed long int\)1: SUCCESS
8-
\[main.overflow.3\] line \d+ pointer arithmetic overflow on \+ in p \+ \(signed long int\)-1: SUCCESS
9-
\[main.overflow.4\] line \d+ pointer arithmetic overflow on - in p - \(signed long int\)-1: SUCCESS
6+
\[main.overflow.1\] line \d+ pointer arithmetic overflow on - in p - \(signed long (long )?int\)1: SUCCESS
7+
\[main.overflow.2\] line \d+ pointer arithmetic overflow on \+ in p \+ \(signed long (long )?int\)1: SUCCESS
8+
\[main.overflow.3\] line \d+ pointer arithmetic overflow on \+ in p \+ \(signed long (long )?int\)-1: SUCCESS
9+
\[main.overflow.4\] line \d+ pointer arithmetic overflow on - in p - \(signed long (long )?int\)-1: SUCCESS
1010
--
1111
^warning: ignoring

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)