Skip to content

Commit f803197

Browse files
committed
Add a test based on the conversion of casting of pointer values
1 parent c47678d commit f803197

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
int cmp(const void *p1, const void *p2)
2+
{
3+
int x = *(int *)p1;
4+
int y = *(int *)p2;
5+
6+
return (x < y) ? -1 : ((x == y) ? 0 : 1);
7+
}
8+
9+
int main()
10+
{
11+
int a = 5;
12+
int b = 6;
13+
int c = 7;
14+
15+
__CPROVER_assert(cmp(&a, &b) == -1, "expected result == -1: success");
16+
__CPROVER_assert(cmp(&c, &b) == 1, "expected result == 1: success");
17+
__CPROVER_assert(cmp(&c, &c) == 0, "expected result == 0: success");
18+
__CPROVER_assert(cmp(&c, &c) == 1, "expected result == 1: failure");
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
pointer_to_int.c
3+
--trace
4+
\[main\.assertion\.1\] line \d+ expected result == -1: success: SUCCESS
5+
\[main\.assertion\.2\] line \d+ expected result == 1: success: SUCCESS
6+
\[main\.assertion\.3\] line \d+ expected result == 0: success: SUCCESS
7+
\[main\.assertion\.4\] line \d+ expected result == 1: failure: FAILURE
8+
^VERIFICATION FAILED$
9+
^EXIT=10$
10+
^SIGNAL=0$
11+
--
12+
--
13+
This test is covering basic conversion of casting of different pointer values,
14+
which are then dereferenced and used in the function. We are asserting against
15+
the result of the function, which cannot be right, unless the conversions
16+
work as they should.

0 commit comments

Comments
 (0)