Skip to content

Commit e27b6b5

Browse files
Fix string non empty option
1 parent aab3e8f commit e27b6b5

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
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: 14 additions & 14 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()))
@@ -1044,15 +1044,15 @@ void java_object_factoryt::gen_nondet_struct_init(
10441044
// If the initialised type is a special-cased String type (one with length
10451045
// and data fields introduced by string-library preprocessing), initialise
10461046
// those fields with nondet values:
1047-
skip_special_string_fields =
1048-
initialize_nondet_string_fields(
1049-
to_struct_expr(initial_object),
1050-
assignments,
1051-
object_factory_parameters.max_nondet_string_length,
1052-
loc,
1053-
object_factory_parameters.function_id,
1054-
symbol_table,
1055-
object_factory_parameters.string_printable);
1047+
skip_special_string_fields = initialize_nondet_string_fields(
1048+
to_struct_expr(initial_object),
1049+
assignments,
1050+
object_factory_parameters.min_nondet_string_length,
1051+
object_factory_parameters.max_nondet_string_length,
1052+
loc,
1053+
object_factory_parameters.function_id,
1054+
symbol_table,
1055+
object_factory_parameters.string_printable);
10561056

10571057
assignments.copy_to_operands(
10581058
code_assignt(expr, initial_object));

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)