File tree 4 files changed +67
-0
lines changed
invar_check_pointer_modifies-01
invar_check_pointer_modifies-02 4 files changed +67
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+ #include <stdlib.h>
3
+
4
+ void main ()
5
+ {
6
+ char * data = malloc (1 );
7
+ * data = 42 ;
8
+
9
+ unsigned i ;
10
+ while (i > 0 )
11
+ __CPROVER_loop_invariant (* data == 42 )
12
+ {
13
+ * data = 42 ;
14
+ i -- ;
15
+ }
16
+
17
+ assert (* data = 42 );
18
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --enforce-all-contracts --pointer-check
4
+ ^EXIT=0$
5
+ ^SIGNAL=0$
6
+ ^\[main.1\] .* Check loop invariant before entry: SUCCESS$
7
+ ^\[main.2\] .* Check that loop invariant is preserved: SUCCESS$
8
+ ^\[main.assertion.1\] .* assertion \*data = 42: SUCCESS$
9
+ ^VERIFICATION SUCCESSFUL$
10
+ --
11
+ ^\[main.pointer_dereference.*\] line .* dereference failure: pointer NULL in \*data: FAILURE
12
+ --
13
+ This test checks that modifications to deref-ed pointers are correctly handled.
14
+ In such cases, pointers should not be havoc'ed, only the value should be.
Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+ #include <stdlib.h>
3
+
4
+ void main ()
5
+ {
6
+ char * copy , * data = malloc (1 );
7
+
8
+ copy = data ;
9
+ * data = 42 ;
10
+
11
+ unsigned i ;
12
+ while (i > 0 )
13
+ __CPROVER_loop_invariant (* data == 42 )
14
+ {
15
+ * data = 42 ;
16
+ i -- ;
17
+ }
18
+
19
+ assert (data == copy );
20
+ assert (* copy = 42 );
21
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --enforce-all-contracts --pointer-check
4
+ ^EXIT=0$
5
+ ^SIGNAL=0$
6
+ ^\[main.1\] .* Check loop invariant before entry: SUCCESS$
7
+ ^\[main.2\] .* Check that loop invariant is preserved: SUCCESS$
8
+ ^\[main.assertion.1\] .* assertion data == copy: SUCCESS$
9
+ ^\[main.assertion.2\] .* assertion \*copy = 42: SUCCESS$
10
+ ^VERIFICATION SUCCESSFUL$
11
+ --
12
+ ^\[main.pointer_dereference.*\] line .* dereference failure: pointer NULL in \*data: FAILURE
13
+ --
14
+ This test checks that modifications to aliased pointers are correctly handled.
You can’t perform that action at this time.
0 commit comments