Skip to content

Commit dcf7614

Browse files
Correcting replace_string_methods to not overwrite the map we iterate on
The previous implementation was writing in the map while iterating on it which could cause some bugs. The new implementation does this in two steps to avoid the problem.
1 parent ca32a0a commit dcf7614

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/java_bytecode/java_bytecode_language.cpp

+16-9
Original file line numberDiff line numberDiff line change
@@ -812,17 +812,24 @@ Function: java_bytecode_languaget::replace_string_methods
812812
void java_bytecode_languaget::replace_string_methods(
813813
symbol_tablet &context)
814814
{
815-
for(auto &id_symbol_pair : context.symbols)
815+
// Symbols that have code type are potentialy to be replaced
816+
std::list<symbolt> code_symbols;
817+
forall_symbols(symbol, context.symbols)
816818
{
817-
const irep_idt &id=id_symbol_pair.first;
818-
symbolt &symbol=id_symbol_pair.second;
819-
if(symbol.type.id()==ID_code)
819+
if(symbol->second.type.id()==ID_code)
820+
code_symbols.push_back(symbol->second);
821+
}
822+
823+
for(const auto &symbol : code_symbols)
824+
{
825+
const irep_idt &id=symbol.name;
826+
exprt generated_code=string_preprocess.code_for_function(
827+
id, to_code_type(symbol.type), symbol.location, context);
828+
if(generated_code.is_not_nil())
820829
{
821-
exprt generated_code=string_preprocess.code_for_function(
822-
id, to_code_type(symbol.type), symbol.location, context);
823-
if(generated_code.is_not_nil())
824-
// Replace body of the function by code generated by string preprocess
825-
symbol.value=generated_code;
830+
// Replace body of the function by code generated by string preprocess
831+
symbolt &symbol=context.lookup(id);
832+
symbol.value=generated_code;
826833
}
827834
}
828835
}

0 commit comments

Comments
 (0)