Skip to content

Commit 11f337a

Browse files
committed
Don't try to use named local variables out of scope, even if only one named local uses a particular slot.
(Anonymous locals of different types might use the slot before or afterwards)
1 parent 96156fe commit 11f337a

File tree

1 file changed

+16
-28
lines changed

1 file changed

+16
-28
lines changed

src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -100,34 +100,22 @@ class java_bytecode_convert_methodt:public messaget
100100
variablest &var_list, instruction_sizet inst_size)
101101
{
102102
size_t var_list_length = var_list.size();
103-
if(var_list_length > 1)
104-
{
105-
for(variablet &var : var_list)
106-
{
107-
size_t start_pc = var.start_pc;
108-
size_t length = var.length;
109-
if (address + (size_t) inst_size >= start_pc && address < start_pc + length)
110-
return var;
111-
}
112-
// add unnamed local variable to end of list at this index
113-
// with scope from 0 to INT_MAX
114-
// as it is at the end of the vector, it will only be taken into account
115-
// if no other variable is valid
116-
size_t list_length = var_list.size();
117-
var_list.resize(list_length + 1);
118-
var_list[list_length].start_pc = 0;
119-
var_list[list_length].length = std::numeric_limits<size_t>::max();
120-
return var_list[list_length];
121-
}
122-
else if(var_list_length == 1)
123-
return var_list[0];
124-
else
125-
{
126-
// return reference to unnamed local variable
127-
// if no local variable is defined for this index
128-
var_list.resize(1);
129-
return var_list[0];
130-
}
103+
for(variablet &var : var_list)
104+
{
105+
size_t start_pc = var.start_pc;
106+
size_t length = var.length;
107+
if (address + (size_t) inst_size >= start_pc && address < start_pc + length)
108+
return var;
109+
}
110+
// add unnamed local variable to end of list at this index
111+
// with scope from 0 to INT_MAX
112+
// as it is at the end of the vector, it will only be taken into account
113+
// if no other variable is valid
114+
size_t list_length = var_list.size();
115+
var_list.resize(list_length + 1);
116+
var_list[list_length].start_pc = 0;
117+
var_list[list_length].length = std::numeric_limits<size_t>::max();
118+
return var_list[list_length];
131119
}
132120

133121
// JVM local variables

0 commit comments

Comments
 (0)