Skip to content

Commit 3b406c6

Browse files
authored
Merge pull request #5814 from tautschnig/pointer-overflow-check
Pointer arithmetic overflow is overflow on integer representation
2 parents cc4ab19 + a20fb34 commit 3b406c6

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)