Skip to content

Commit 513b67a

Browse files
Merge pull request #2038 from romainbrenguier/bugfix/assign-at-malloc-site
[TG-3173] Assign Strings at malloc site in java object factory
2 parents 768e8a6 + c207106 commit 513b67a

File tree

5 files changed

+42
-6
lines changed

5 files changed

+42
-6
lines changed
925 Bytes
Binary file not shown.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
public class Test {
2+
3+
public static String check(String[] array) {
4+
// Filter
5+
if(array == null)
6+
return "null array";
7+
if(array.length < 2)
8+
return "too short";
9+
if(array[0] == null)
10+
return "null string";
11+
12+
// Arrange
13+
String s0 = array[0];
14+
String s1 = array[1];
15+
16+
// Act
17+
boolean b = s0.equals(s1);
18+
19+
// Assert
20+
assert(s0 != null);
21+
assert(!b);
22+
23+
// Return
24+
return s0 + s1;
25+
}
26+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
Test.class
3+
--refine-strings --function Test.check --string-max-input-length 1000
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^\[.*assertion\.1\].* line 20.* SUCCESS$
7+
^\[.*assertion\.2\].* line 21.* FAILURE$
8+
--

src/java_bytecode/java_object_factory.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ exprt allocate_dynamic_object(
248248
/// \param symbol_table: symbol table
249249
/// \param loc: location in the source
250250
/// \param output_code: code block to which the necessary code is added
251-
void allocate_dynamic_object_with_decl(
251+
/// \return the dynamic object created
252+
exprt allocate_dynamic_object_with_decl(
252253
const exprt &target_expr,
253254
symbol_table_baset &symbol_table,
254255
const source_locationt &loc,
@@ -257,8 +258,7 @@ void allocate_dynamic_object_with_decl(
257258
std::vector<const symbolt *> symbols_created;
258259
code_blockt tmp_block;
259260
const typet &allocate_type=target_expr.type().subtype();
260-
// We will not use the malloc site and can safely ignore it
261-
(void) allocate_dynamic_object(
261+
const exprt dynamic_object = allocate_dynamic_object(
262262
target_expr,
263263
allocate_type,
264264
symbol_table,
@@ -278,6 +278,7 @@ void allocate_dynamic_object_with_decl(
278278

279279
for(const exprt &code : tmp_block.operands())
280280
output_code.add(to_code(code));
281+
return dynamic_object;
281282
}
282283

283284
/// Installs a new symbol in the symbol table, pushing the corresponding symbolt
@@ -701,11 +702,12 @@ static bool add_nondet_string_pointer_initialization(
701702
if(!struct_type.has_component("data") || !struct_type.has_component("length"))
702703
return true;
703704

704-
allocate_dynamic_object_with_decl(expr, symbol_table, loc, code);
705+
const exprt malloc_site =
706+
allocate_dynamic_object_with_decl(expr, symbol_table, loc, code);
705707

706708
code.add(
707709
initialize_nondet_string_struct(
708-
dereference_exprt(expr, struct_type),
710+
dereference_exprt(malloc_site, struct_type),
709711
max_nondet_string_length,
710712
loc,
711713
symbol_table,

src/java_bytecode/java_object_factory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ exprt allocate_dynamic_object(
146146
std::vector<const symbolt *> &symbols_created,
147147
bool cast_needed = false);
148148

149-
void allocate_dynamic_object_with_decl(
149+
exprt allocate_dynamic_object_with_decl(
150150
const exprt &target_expr,
151151
symbol_table_baset &symbol_table,
152152
const source_locationt &loc,

0 commit comments

Comments
 (0)