Skip to content

Commit ae5f32e

Browse files
Add a printable option to string initialization
This will force characters to be printable when the string is initialized. This is set to false by default for now, but should then be activated when string-printable is given.
1 parent 514e6a1 commit ae5f32e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/java_bytecode/java_object_factory.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,8 @@ codet initialize_nondet_string_struct(
542542
const exprt &obj,
543543
const std::size_t &max_nondet_string_length,
544544
const source_locationt &loc,
545-
symbol_tablet &symbol_table)
545+
symbol_tablet &symbol_table,
546+
bool printable)
546547
{
547548
PRECONDITION(
548549
java_string_library_preprocesst::implements_java_char_sequence(obj.type()));
@@ -605,6 +606,13 @@ codet initialize_nondet_string_struct(
605606

606607
add_array_to_length_association(
607608
data_expr, length_expr, symbol_table, loc, code);
609+
610+
// Printable ASCII characters are between ' ' and '~'.
611+
if(printable)
612+
{
613+
add_character_set_constraint(
614+
array_pointer, length_expr, " -~", symbol_table, loc, code);
615+
}
608616
}
609617

610618
// tmp_object = struct_expr;

src/java_bytecode/java_object_factory.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ codet initialize_nondet_string_struct(
156156
const exprt &obj,
157157
const std::size_t &max_nondet_string_length,
158158
const source_locationt &loc,
159-
symbol_tablet &symbol_table);
159+
symbol_tablet &symbol_table,
160+
bool printable = false);
160161

161162
#endif // CPROVER_JAVA_BYTECODE_JAVA_OBJECT_FACTORY_H

0 commit comments

Comments
 (0)