fix NPE with a string switch if the default case is not the last case block.

This commit is contained in:
Volker Berlin 2020-03-05 22:30:36 +01:00
parent 6923765683
commit f120c40de3

View File

@ -608,13 +608,20 @@ class BranchManger {
if( start > node.endPos ) { if( start > node.endPos ) {
if( end > branch.endPos ) { if( end > branch.endPos ) {
BranchNode parentNode = branch; BranchNode parentNode = branch;
while( end > parentNode.endPos ) { while( parentNode != null && end > parentNode.endPos ) {
parentNode = parentNode.parent; parentNode = parentNode.parent;
} }
BranchNode middleNode = new BranchNode( startPosition, parsedBlock.endPosition, WasmBlockOperator.BLOCK, WasmBlockOperator.END ); BranchNode middleNode = new BranchNode( startPosition, end, WasmBlockOperator.BLOCK, WasmBlockOperator.END );
BranchNode child = parentNode.remove( 0 ); if( parentNode != null ) {
parentNode.add( middleNode ); BranchNode child = parentNode.remove( 0 );
middleNode.add( child ); parentNode.add( middleNode );
middleNode.add( child );
} else {
// occur if the default is not the last case in the switch
middleNode.add( blockNode );
blockNode = middleNode;
lastPosition = end;
}
cases[posCount].block++; cases[posCount].block++;
} }
break; break;
@ -650,7 +657,7 @@ class BranchManger {
WasmBlockOperator startOp; WasmBlockOperator startOp;
if( parsedBlock.op == JavaBlockOperator.GOTO ) { if( parsedBlock.op == JavaBlockOperator.GOTO ) {
startOp = WasmBlockOperator.BR; startOp = WasmBlockOperator.BR;
lastPosition = end; lastPosition = Math.max( lastPosition, end );
} else { } else {
startOp = WasmBlockOperator.BR_IF; startOp = WasmBlockOperator.BR_IF;
} }