Skip to content

Commit c9e1281

Browse files
Use a model of String constructor from charArray
The version in the preprocessing was not working correctly for non constant arrays, so we will get rid of it and it's better to use a model of the constructor.
1 parent bbf0d02 commit c9e1281

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

jbmc/regression/jbmc-strings/java_append_char/test.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ test_append_char.class
44
^EXIT=10$
55
^SIGNAL=0$
66
^VERIFICATION FAILED$
7-
^\[.*assertion\.1\].* line 16.* SUCCESS$
8-
^\[.*assertion\.2\].* line 18.* FAILURE$
7+
^\[.*assertion\.1\].* line 29.* SUCCESS$
8+
^\[.*assertion\.2\].* line 31.* FAILURE$
99
--
Binary file not shown.
Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
1+
// This test uses CProverString so should be compiled with
2+
// javac test_append_char.java ../cprover/CProverString.java ../cprover/CProver.java
3+
14
public class test_append_char
25
{
3-
public static void main(boolean b)
4-
{
5-
char[] diff = {'d', 'i', 'f', 'f'};
6-
char[] blue = {'b', 'l', 'u', 'e'};
7-
8-
StringBuilder buffer = new StringBuilder();
6+
public static String ofCharArray(char value[], int offset, int count) {
7+
org.cprover.CProver.assume(value != null);
8+
org.cprover.CProver.assume(value.length - count >= offset
9+
&& offset >= 0 && count >= 0);
10+
StringBuilder builder = new StringBuilder();
11+
for(int i = 0; i < count; i++) {
12+
builder.append(value[offset + i]);
13+
}
14+
return builder.toString();
15+
}
916

10-
buffer.append(diff)
11-
.append(blue);
17+
public static String main(boolean b)
18+
{
19+
char[] diff = {'d', 'i', 'f', 'f'};
20+
char[] blue = {'b', 'l', 'u', 'e'};
1221

13-
String tmp=buffer.toString();
14-
System.out.println(tmp);
15-
if(b)
16-
assert(tmp.equals("diffblue"));
17-
else
18-
assert(!tmp.equals("diffblue"));
19-
}
22+
StringBuilder buffer = new StringBuilder();
23+
String s = ofCharArray(diff, 0, diff.length);
24+
buffer.append(ofCharArray(diff, 0, diff.length))
25+
.append(ofCharArray(blue, 0, blue.length));
26+
String tmp=buffer.toString();
27+
System.out.println(tmp);
28+
if(b)
29+
assert(tmp.equals("diffblue"));
30+
else
31+
assert(!tmp.equals("diffblue"));
32+
return tmp;
33+
}
2034
}

0 commit comments

Comments
 (0)