Skip to content

Commit 62b5536

Browse files
Fix string non empty option
1 parent aab3e8f commit 62b5536

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

jbmc/src/java_bytecode/java_bytecode_language.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ void java_bytecode_languaget::get_language_options(const cmdlinet &cmd)
8585
object_factory_parameters.max_nondet_string_length =
8686
safe_string2size_t(cmd.get_value("max-nondet-string-length"));
8787
}
88+
if(cmd.isset("string-non-empty"))
89+
object_factory_parameters.min_nondet_string_length = 1;
8890

8991
object_factory_parameters.string_printable = cmd.isset("string-printable");
9092
if(cmd.isset("java-max-vla-length"))

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ static codet make_allocate_code(const symbol_exprt &lhs, const exprt &size)
573573
bool initialize_nondet_string_fields(
574574
struct_exprt &struct_expr,
575575
code_blockt &code,
576+
const std::size_t &min_nondet_string_length,
576577
const std::size_t &max_nondet_string_length,
577578
const source_locationt &loc,
578579
const irep_idt &function_id,
@@ -627,11 +628,10 @@ bool initialize_nondet_string_fields(
627628
code.add(code_declt(length_expr));
628629
code.add(code_assignt(length_expr, nondet_length));
629630

630-
// assume (length_expr >= 0);
631-
code.add(
632-
code_assumet(
633-
binary_relation_exprt(
634-
length_expr, ID_ge, from_integer(0, java_int_type()))));
631+
// assume (length_expr >= min_nondet_string_length);
632+
const exprt min_length =
633+
from_integer(min_nondet_string_length, java_int_type());
634+
code.add(code_assumet(binary_relation_exprt(length_expr, ID_ge, min_length)));
635635

636636
// assume (length_expr <= max_input_length)
637637
if(max_nondet_string_length <= max_value(length_expr.type()))
@@ -1048,6 +1048,7 @@ void java_object_factoryt::gen_nondet_struct_init(
10481048
initialize_nondet_string_fields(
10491049
to_struct_expr(initial_object),
10501050
assignments,
1051+
object_factory_parameters.min_nondet_string_length,
10511052
object_factory_parameters.max_nondet_string_length,
10521053
loc,
10531054
object_factory_parameters.function_id,

jbmc/src/java_bytecode/object_factory_parameters.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ struct object_factory_parameterst final
2828
/// Maximum value for the non-deterministically-chosen length of a string.
2929
size_t max_nondet_string_length=MAX_NONDET_STRING_LENGTH;
3030

31+
/// Maximum value for the non-deterministically-chosen length of a string.
32+
size_t min_nondet_string_length = 0;
33+
3134
/// Maximum depth for object hierarchy on input.
3235
/// Used to prevent object factory to loop infinitely during the
3336
/// generation of code that allocates/initializes data structures of recursive

0 commit comments

Comments
 (0)