Skip to content

Commit 80f93c0

Browse files
Fix invalid maybe null initialization of Strings
The initialization of String arrays was broken. It was impossible to create a String array that is non-null or maybe-null. When jbmc is run without a valid model for the String class (which makes little sense anyways) then a String object cannot be instantiated in the harness; the initialization will be null in this case.
1 parent 4f3b9ae commit 80f93c0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,8 @@ static bool add_nondet_string_pointer_initialization(
683683
const struct_typet &struct_type =
684684
to_struct_type(ns.follow(to_symbol_type(obj.type())));
685685

686-
if(!struct_type.has_component("data") || !struct_type.has_component("length"))
686+
// if no String model is loaded then we cannot construct a String object
687+
if(struct_type.get_bool(ID_incomplete_class))
687688
return true;
688689

689690
const exprt malloc_site = allocate_dynamic_object_with_decl(
@@ -867,8 +868,7 @@ void java_object_factoryt::gen_nondet_pointer_init(
867868

868869
// Alternatively, if this is a void* we *must* initialise with null:
869870
// (This can currently happen for some cases of #exception_value)
870-
bool must_be_null=
871-
subtype==empty_typet();
871+
bool must_be_null = subtype == empty_typet();
872872

873873
if(must_be_null)
874874
{

0 commit comments

Comments
 (0)