Skip to content

Commit 19947e9

Browse files
committed
History variables do not check for nullness
Signed-off-by: Felipe R. Monteiro <[email protected]>
1 parent a80b65a commit 19947e9

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <stdlib.h>
2+
3+
struct pair
4+
{
5+
int x;
6+
int y;
7+
};
8+
9+
void foo(struct pair *p) __CPROVER_assigns(p->y)
10+
__CPROVER_ensures((p != NULL) == > (p->y == __CPROVER_old(p->y) + 5))
11+
__CPROVER_ensures((p == NULL) == > (p->y == __CPROVER_old(p->y)))
12+
{
13+
if(p != NULL)
14+
p->y = p->y + 5;
15+
}
16+
17+
int main()
18+
{
19+
struct pair *p = NULL;
20+
foo(p);
21+
22+
return 0;
23+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
KNOWNBUG
2+
main.c
3+
--enforce-all-contracts
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[postcondition.\d+\] Check ensures clause\: SUCCESS$
7+
^\[foo.\d+\] line \d+ Check that p\-\>y is assignable\: SUCCESS$
8+
^VERIFICATION SUCCESSFUL$
9+
--
10+
--
11+
This test checks that history variables handle NULL pointers.
12+
History variables currently do not check for nullness while
13+
storing values of objects, which may lead to NULL pointer dereferences.

0 commit comments

Comments
 (0)