Skip to content

Commit 2662cad

Browse files
committed
Fix symbol table alteration during iteration
As usual it's illegal to add symbols during an iteration over the same table, so I find the functions to alter and store them in a temporary, looking each up in turn.
1 parent 96826e7 commit 2662cad

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/java_bytecode/java_bytecode_instrument.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,19 @@ void java_bytecode_instrument(
600600
max_array_length,
601601
max_tree_depth);
602602

603-
Forall_symbols(s_it, symbol_table.symbols)
603+
std::vector<irep_idt> symbols_to_instrument;
604+
forall_symbols(s_it, symbol_table.symbols)
604605
{
605606
if(s_it->second.value.id()==ID_code)
606-
instrument(s_it->second.value);
607+
symbols_to_instrument.push_back(s_it->first);
608+
}
609+
610+
// instrument(...) can add symbols to the table, so it's
611+
// not safe to hold a reference to a symbol across a call.
612+
for(const auto &symbol : symbols_to_instrument)
613+
{
614+
exprt value=symbol_table.lookup(symbol).value;
615+
instrument(value);
616+
symbol_table.lookup(symbol).value=value;
607617
}
608618
}

0 commit comments

Comments
 (0)