Skip to content

Commit f3b1379

Browse files
Merge pull request diffblue#1975 from romainbrenguier/bugfix/literal-length-TG2878
[TG-2878] Fix bug in literal lengths
2 parents 2a0927c + 56c9c02 commit f3b1379

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed
623 Bytes
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class Test {
2+
public static int check(int i) {
3+
String s = "\u0000";
4+
5+
if (i == 0)
6+
assert(s.length() == 1);
7+
else if (i == 1)
8+
assert(s.length() != 1);
9+
10+
return s.length();
11+
}
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
Test.class
3+
--refine-strings --function Test.check
4+
assertion at file Test.java line 6 .* SUCCESS
5+
assertion at file Test.java line 8 .* FAILURE
6+
^EXIT=10$
7+
^SIGNAL=0$

src/java_bytecode/java_string_literals.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,17 @@ symbol_exprt get_or_create_string_literal_symbol(
106106
// contents as well:
107107
if(string_refinement_enabled)
108108
{
109+
const array_exprt data =
110+
utf16_to_array(utf8_to_utf16_little_endian(id2string(value)));
111+
109112
struct_exprt literal_init(new_symbol.type);
110113
literal_init.operands().resize(jls_struct.components().size());
111114
const std::size_t jlo_nb = jls_struct.component_number("@java.lang.Object");
112115
literal_init.operands()[jlo_nb] = jlo_init;
113116

114117
const std::size_t length_nb = jls_struct.component_number("length");
115118
const typet &length_type = jls_struct.components()[length_nb].type();
116-
const exprt length = from_integer(id2string(value).size(), length_type);
119+
const exprt length = from_integer(data.operands().size(), length_type);
117120
literal_init.operands()[length_nb] = length;
118121

119122
// Initialize the string with a constant utf-16 array:
@@ -127,8 +130,7 @@ symbol_exprt get_or_create_string_literal_symbol(
127130
// These are basically const global data:
128131
array_symbol.is_static_lifetime = true;
129132
array_symbol.is_state_var = true;
130-
array_symbol.value =
131-
utf16_to_array(utf8_to_utf16_little_endian(id2string(value)));
133+
array_symbol.value = data;
132134
array_symbol.type = array_symbol.value.type();
133135

134136
if(symbol_table.add(array_symbol))

0 commit comments

Comments
 (0)