@@ -39,15 +39,16 @@ public class ExampleArray {
39
39
Now let's run the following command to let JBMC tell us about potential errors
40
40
in our ` query ` method.
41
41
42
- jbmc ExampleArray.class --function tutorial.ExampleArray.query
42
+ $ jbmc ExampleArray.class --function tutorial.ExampleArray.query
43
43
44
44
45
45
The output contains the following:
46
-
47
- [java::tutorial.ExampleArray.query:([II)I.null-pointer-exception.1] line 6 Null pointer check: FAILURE
48
- [java::tutorial.ExampleArray.query:([II)I.array-index-out-of-bounds-low.1] line 6 Array index should be >= 0: FAILURE
49
- [java::tutorial.ExampleArray.query:([II)I.array-index-out-of-bounds-high.1] line 6 Array index should be < length: FAILURE
50
- [java::tutorial.ExampleArray.query:([II)I.1] line 6 no uncaught exception: SUCCESS
46
+ ``` c
47
+ [java::tutorial.ExampleArray.query:([II)I.null-pointer-exception.1 ] line 6 Null pointer check: FAILURE
48
+ [java::tutorial.ExampleArray.query:([II)I.array-index-out-of-bounds-low.1 ] line 6 Array index should be >= 0 : FAILURE
49
+ [java::tutorial.ExampleArray.query:([II)I.array-index-out-of-bounds-high.1 ] line 6 Array index should be < length: FAILURE
50
+ [java::tutorial.ExampleArray.query:([II)I.1 ] line 6 no uncaught exception: SUCCESS
51
+ ```
51
52
52
53
Three reported failures spring up:
53
54
1 . there is no null pointer check on the array passed as argument
@@ -74,13 +75,13 @@ public class ExampleArraySafe {
74
75
```
75
76
then the JBMC automatic assertions become valid, meaning that there is no
76
77
possible inputs (argument values) for which they can be violated:
77
-
78
- [java::tutorial.ExampleArraySafe.query:([II)I.1] line 6 no uncaught exception: SUCCESS
79
- [java::tutorial.ExampleArraySafe.query:([II)I.null-pointer-exception.1] line 9 Null pointer check: SUCCESS
80
- [java::tutorial.ExampleArraySafe.query:([II)I.null-pointer-exception.2] line 12 Null pointer check: SUCCESS
81
- [java::tutorial.ExampleArraySafe.query:([II)I.array-index-out-of-bounds-low.1] line 12 Array index should be >= 0: SUCCESS
82
- [java::tutorial.ExampleArraySafe.query:([II)I.array-index-out-of-bounds-high.1] line 12 Array index should be < length: SUCCESS
83
-
78
+ ``` c
79
+ [java::tutorial.ExampleArraySafe.query:([II)I.1 ] line 6 no uncaught exception: SUCCESS
80
+ [java::tutorial.ExampleArraySafe.query:([II)I.null-pointer-exception.1 ] line 9 Null pointer check: SUCCESS
81
+ [java::tutorial.ExampleArraySafe.query:([II)I.null-pointer-exception.2 ] line 12 Null pointer check: SUCCESS
82
+ [java::tutorial.ExampleArraySafe.query:([II)I.array-index-out-of-bounds-low.1 ] line 12 Array index should be >= 0 : SUCCESS
83
+ [java::tutorial.ExampleArraySafe.query:([II)I.array-index-out-of-bounds-high.1 ] line 12 Array index should be < length: SUCCESS
84
+ ```
84
85
85
86
\subsection jbmc-manual-unwind Loop unwinding
86
87
@@ -116,9 +117,10 @@ public class ExampleUnwind {
116
117
To limit the number of times the for-loop is unwound, we use the ` --unwind N `
117
118
options, in which case the following call to JBMC:
118
119
119
- jbmc ExampleUnwind.class --function tutorial.ExampleUnwind.isPrime --unwind 10
120
+ $ jbmc ExampleUnwind.class --function tutorial.ExampleUnwind.isPrime --unwind 10
120
121
121
- will terminate (with ` VERIFICATION SUCCESSFUL ` ).
122
+ will terminate correctly. In this case, we will see ` VERIFICATION SUCCESSFUL ` ,
123
+ as no automatic assertions are violated.
122
124
123
125
124
126
\subsection jbmc-manual-user-assert User assertions
@@ -128,20 +130,20 @@ JBMC will try do refute. On line 7, we check the assertion that all odd
128
130
numbers greater than 1 are prime. To be sure that this always holds, we run
129
131
JBMC on the example, with a reasonable ` unwind ` value:
130
132
131
- jbmc ExampleUnwind.class --function tutorial.ExampleUnwind.doSomething --unwind 10
133
+ $ jbmc ExampleUnwind.class --function tutorial.ExampleUnwind.doSomething --unwind 10
132
134
133
135
Unsurprisingly JBMC doesn't agree, and prints an assertion failure
134
136
(truncated here for readability):
135
-
136
- [...doSomething:(I)V.assertion.1] line 7 assertion at file tutorial/ExampleUnwind.java: FAILURE
137
-
137
+ ``` c
138
+ [...doSomething:(I)V.assertion.1 ] line 7 assertion at file tutorial/ExampleUnwind.java: FAILURE
139
+ ```
138
140
139
141
Rerunning the analysis with the ` --trace ` option, the following line appears
140
142
somewhere in the trace output and tells us which input value JBMC found to
141
143
trigger the violation:
142
-
143
- INPUT inputVal: 15
144
-
144
+ ``` c
145
+ INPUT inputVal: 15
146
+ ```
145
147
The value chosen by JBMC is arbitrary, and could as well be 9
146
148
or 2084569161.
147
149
Note that to see the original parameter names in the trace
@@ -178,16 +180,16 @@ public class ExampleModels {
178
180
The following command line (note that the current directory is also added to
179
181
the classpath):
180
182
181
- jbmc ExampleModels.class --function tutorial.ExampleModels.stringOp --cp <path_to_cbmc>/jbmc/src/java_bytecode/library/core-models.jar:.
183
+ $ jbmc ExampleModels.class --function tutorial.ExampleModels.stringOp --cp <path_to_cbmc>/jbmc/src/java_bytecode/library/core-models.jar:.
182
184
183
185
will flag this violation (truncated):
184
-
185
- [java::tutorial.ExampleModels.stringOp:()V.assertion.1] line 8 assertion: FAILURE
186
-
186
+ ``` c
187
+ [java::tutorial.ExampleModels.stringOp:()V.assertion.1 ] line 8 assertion: FAILURE
188
+ ```
187
189
Again, the trace shows the string violating the condition in the assertion:
188
-
189
- dynamic_object2={ 'a', 'b', '$', 'c', 'd' }
190
-
190
+ ``` c
191
+ dynamic_object2={ 'a', 'b', '$', 'c', 'd' }
192
+ ```
191
193
192
194
\subsection jbmc-manual-exceptions Exceptions
193
195
@@ -231,5 +233,5 @@ JBMC has a wealth of other options that can either constrain the model (to
231
233
cope with complexity issues), or output more relevant information. The list
232
234
of all available options is printed by running:
233
235
234
- jbmc --help
236
+ $ jbmc --help
235
237
0 commit comments