Skip to content

Commit 6b03fac

Browse files
committed
Tighten regression tests for pointer subtraction.
This is to make sure that we get reasonable results from a pointer subtraction operation, and that the invariants between the different base types are observed.
1 parent 8c8fa40 commit 6b03fac

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed
Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
#define NULL (void *)0
2-
1+
#include <stdlib.h>
32
int main()
43
{
5-
int *x;
6-
int *y;
7-
int *z = x - y;
8-
__CPROVER_assume(x != NULL);
9-
__CPROVER_assume(y != NULL);
10-
__CPROVER_assume(x != y);
11-
12-
__CPROVER_assert(z == x, "expected failure after pointer manipulation");
13-
__CPROVER_assert(z == y, "expected failure after pointer manipulation");
14-
__CPROVER_assert(y != x, "expected succesful after pointer manipulation");
4+
int *x = malloc(sizeof(int));
5+
int *y = x + 3;
6+
int z = y - x;
7+
__CPROVER_assert(y == x, "expected failure after pointer manipulation");
8+
__CPROVER_assert(z == 3, "expected successful after pointer manipulation");
9+
__CPROVER_assert(z != 3, "expected failure after pointer manipulation");
1510
}

regression/cbmc-incr-smt2/pointer_arithmetic/pointer_subtraction.desc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
CORE
22
pointer_subtraction.c
33
--trace
4-
\[main\.assertion\.1] line \d+ expected failure after pointer manipulation: FAILURE
5-
\[main\.assertion\.2] line \d+ expected failure after pointer manipulation: FAILURE
6-
\[main\.assertion\.3] line \d+ expected succesful after pointer manipulation: SUCCESS
4+
\[main\.assertion\.1\] line \d+ expected failure after pointer manipulation: FAILURE
5+
\[main\.assertion\.2\] line \d+ expected successful after pointer manipulation: SUCCESS
6+
\[main\.assertion\.3\] line \d+ expected failure after pointer manipulation: FAILURE
7+
z=3
78
^EXIT=10$
89
^SIGNAL=0$
910
--
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <stdlib.h>
2+
int main()
3+
{
4+
int *x = malloc(sizeof(int));
5+
float *y = x + 3;
6+
int z = y - x;
7+
__CPROVER_assert(y == x, "expected failure after pointer manipulation");
8+
__CPROVER_assert(z == 3, "expected successful after pointer manipulation");
9+
__CPROVER_assert(z != 3, "expected failure after pointer manipulation");
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
pointer_subtraction_diff_types.c
3+
--trace
4+
^Reason: only pointers of the same object type can be subtracted.
5+
^EXIT=134$
6+
^SIGNAL=0$
7+
--
8+
--
9+
This test is for making sure that we only subtract pointers with the
10+
same underlying (base) type.

0 commit comments

Comments
 (0)