Skip to content

Commit a87831d

Browse files
authored
Merge pull request #2133 from MarcMil/fixdex
.NET: Fix a problem for empty catch handlers
2 parents 31aed29 + e9dd718 commit a87831d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/main/java/soot/dotnet/instructions/CatchFilterHandlerBody.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,19 @@ public Body getFilterHandlerBody(Value generalExceptionVariable) {
9494
ConditionExpr cond = Jimple.v().newEqExpr(returnValue, IntConstant.v(0));
9595
IfStmt ifRetCondStmt = Jimple.v().newIfStmt(cond, filterCondFalseNop); // if ret==0 ignore handler
9696
// jump to end of filter instructions - cond true
97-
GotoStmt gotoHandlerBodyCondTrueStmt = Jimple.v().newGotoStmt(handlerBody.getUnits().getFirst());
97+
if (!handlerBody.getUnits().isEmpty()) {
98+
//this may happen when there is an empty handler
99+
GotoStmt gotoHandlerBodyCondTrueStmt = Jimple.v().newGotoStmt(handlerBody.getUnits().getFirst());
98100

99-
handlerFilterContainerBlockBody.getUnits().insertAfter(gotoHandlerBodyCondTrueStmt, returnStmt);
101+
handlerFilterContainerBlockBody.getUnits().insertAfter(gotoHandlerBodyCondTrueStmt, returnStmt);
102+
}
100103
handlerFilterContainerBlockBody.getUnits().swapWith(returnStmt, ifRetCondStmt);
101104
dotnetBody.blockEntryPointsManager.swapGotoEntryUnit(ifRetCondStmt, returnStmt);
102105
}
103106
jb.getUnits().addAll(handlerFilterContainerBlockBody.getUnits());
104107

105108
// handler body
106-
if (lastStmtIsNotReturn(handlerBody)) {
109+
if (handlerBody.getUnits().isEmpty() || lastStmtIsNotReturn(handlerBody)) {
107110
// if last stmt is not return, insert goto stmt, to go to end whole block
108111
handlerBody.getUnits().add(Jimple.v().newGotoStmt(nopStmtEnd));
109112
}

0 commit comments

Comments
 (0)