Skip to content

Commit 86a595a

Browse files
authored
Merge pull request diffblue#4198 from smowton/smowton/fix/initialise-classid-strings
Ensure String literals that are only used as classids are initialised
2 parents f6dea89 + 0ef977c commit 86a595a

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed
673 Bytes
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
test.class
3+
--function test.main --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
\[java::test\.main:\(\)V\.assertion\.1\] line 5 assertion at file test\.java line 5 function java::test\.main:\(\)V bytecode-index 8: SUCCESS$
8+
\[java::test\.main:\(\)V\.assertion\.2\] line 6 assertion at file test\.java line 6 function java::test\.main:\(\)V bytecode-index 19: SUCCESS$
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
public class test {
2+
3+
public static void main() {
4+
5+
assert test.class.getName() != null;
6+
assert test.class.getName().length() == 4;
7+
8+
}
9+
10+
}

jbmc/src/java_bytecode/java_entry_point.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Author: Daniel Kroening, [email protected]
1010

1111
#include <util/config.h>
1212
#include <util/expr_initializer.h>
13+
#include <util/journalling_symbol_table.h>
1314
#include <util/string_constant.h>
1415
#include <util/suffix.h>
1516

@@ -154,8 +155,14 @@ static void java_static_lifetime_init(
154155
for(const auto &entry : symbol_table.symbols)
155156
symbol_names.push_back(entry.first);
156157

157-
for(const auto &symname : symbol_names)
158+
// Don't use a for-each loop here because the loop extends the list, and the
159+
// for-each loop may only read `.end()` once.
160+
for(
161+
auto symbol_it = symbol_names.begin();
162+
symbol_it != symbol_names.end();
163+
++symbol_it)
158164
{
165+
const auto &symname = *symbol_it;
159166
const symbolt &sym=*symbol_table.lookup(symname);
160167
if(should_init_symbol(sym))
161168
{
@@ -172,9 +179,17 @@ static void java_static_lifetime_init(
172179
exprt name_literal(ID_java_string_literal);
173180
name_literal.set(ID_value, to_class_type(class_symbol.type).get_tag());
174181

182+
journalling_symbol_tablet journalling_table =
183+
journalling_symbol_tablet::wrap(symbol_table);
184+
175185
symbol_exprt class_name_literal =
176186
get_or_create_string_literal_symbol(
177-
name_literal, symbol_table, string_refinement_enabled);
187+
name_literal, journalling_table, string_refinement_enabled);
188+
189+
// If that created any new symbols make sure we initialise those too:
190+
const auto &new_symbols = journalling_table.get_inserted();
191+
symbol_names.insert(
192+
symbol_names.end(), new_symbols.begin(), new_symbols.end());
178193

179194
// Call the literal initializer method instead of a nondet initializer:
180195

0 commit comments

Comments
 (0)