Skip to content

Fixed indexOutOfBounds bug when the last bytecode of a function has 0 size#9

Open
onlinecco wants to merge 1 commit intopsuter:masterfrom
onlinecco:bugfix
Open

Fixed indexOutOfBounds bug when the last bytecode of a function has 0 size#9
onlinecco wants to merge 1 commit intopsuter:masterfrom
onlinecco:bugfix

Conversation

@onlinecco
Copy link

If a label or any bytecode with size 0 is the last bytecode of a function. There will be an index out of bounds exception at at cafebabe.CodeHandler$$anonfun$computeMaxStack$1.apply(CodeHandler.scala:156)

This is caused by the following code in CodeHandler.scala

val actualSize = abcList.map(_.size).sum
val codeArray = new Array[AbstractByteCode](actualSize)

locally {
  var pc = 0
  for(abc <- abcList) {
    codeArray(pc) = abc
    pc += abc.size
  }
}

actualSize is calculated as the sum of size of all instructions where the size of a label instruction is 0. But if a label is at the end of the bytecode list, and the value of pc will equal to the the calculated actualSize therefore caused the index out of bounds exception on the codeArray.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant