Skip to content

Commit b748552

Browse files
committed
Add regression tests for the subtraction of two pointer values
1 parent 12b23a7 commit b748552

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#define NULL (void *)0
2+
3+
int main()
4+
{
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");
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
pointer_subtraction.c
3+
--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
7+
^EXIT=10$
8+
^SIGNAL=0$
9+
--
10+
--
11+
This test is testing that the subtraction between two pointers (giving us the
12+
increment between the two pointers) works as it should.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#define NULL (void *)0
2+
3+
int main()
4+
{
5+
int *x;
6+
unsigned int z;
7+
__CPROVER_assume(z < 3);
8+
__CPROVER_assume(z > 1);
9+
int *y = x - z;
10+
__CPROVER_assume(x != NULL);
11+
__CPROVER_assume(y != NULL);
12+
13+
__CPROVER_assert(y == x, "expected failure after pointer manipulation");
14+
__CPROVER_assert(y != x, "expected success after pointer manipulation");
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
pointer_subtraction_unsigned.c
3+
--trace
4+
\[main\.assertion\.1\] line \d+ expected failure after pointer manipulation: FAILURE
5+
\[main\.assertion\.2\] line \d+ expected success after pointer manipulation: SUCCESS
6+
^EXIT=10$
7+
^SIGNAL=0$
8+
--
9+
--
10+
The test is similar to the one in `pointer_subtraction.desc`, but with different
11+
types in the subtraction operands.

0 commit comments

Comments
 (0)