Prevent crash when calling insertInstruction() on empty MethodBody

If an AVM2Code object is empty, and we attempt to insert an instruction, the method will execute code.get(-1) and throw an exception. This commit handles the situation.
This commit is contained in:
MultiplyByZer0
2017-03-11 21:58:27 -05:00
parent 3e99d19a1d
commit 2c85203985
@@ -2371,7 +2371,9 @@ public class AVM2Code implements Cloneable {
pos = code.size();
}
final int byteCount = instruction.getBytesLength();
if (pos == code.size()) {
if (code.size() == 0) {
instruction.setAddress(0);
} else if (pos == code.size()) {
instruction.setAddress(code.get(pos - 1).getAddress() + code.get(pos - 1).getBytesLength());
} else {
instruction.setAddress(code.get(pos).getAddress());