Skip to content

Commit f490894

Browse files
smowtonthk123
authored and
thk123
committed
Java method converter: don't hold a symbol table reference across table add operations
This is generally illegal (but is tricky to trigger, hence no test)
1 parent ec41608 commit f490894

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,14 @@ void java_bytecode_convert_methodt::convert(
428428
id2string(class_symbol.name)+"."+id2string(m.name)+":"+m.descriptor;
429429
method_id=method_identifier;
430430

431-
symbolt &method_symbol=*symbol_table.get_writeable(method_identifier);
432-
433431
// Obtain a std::vector of java_method_typet::parametert objects from the
434432
// (function) type of the symbol
435-
java_method_typet method_type = to_java_method_type(method_symbol.type);
433+
// Don't try to hang on to this reference into the symbol table, as we're
434+
// about to create symbols for the method's parameters, which would invalidate
435+
// the reference. Instead, copy the type here, set it up, then assign it back
436+
// to the symbol later.
437+
java_method_typet method_type =
438+
to_java_method_type(symbol_table.lookup_ref(method_identifier).type);
436439
method_type.set(ID_C_class, class_symbol.name);
437440
method_type.set_is_final(m.is_final);
438441
method_return_type = method_type.return_type();
@@ -555,6 +558,8 @@ void java_bytecode_convert_methodt::convert(
555558
param_index+=java_local_variable_slots(param.type());
556559
}
557560

561+
symbolt &method_symbol = symbol_table.get_writeable_ref(method_identifier);
562+
558563
// The parameter slots detected in this function should agree with what
559564
// java_parameter_count() thinks about this method
560565
INVARIANT(

0 commit comments

Comments
 (0)