Browse Source

BlockBuilder: avoid crash on invalid branches (#902)

pull/904/head
Daniel Grunwald 8 years ago
parent
commit
75a65380f0
  1. 8
      ICSharpCode.Decompiler/IL/BlockBuilder.cs

8
ICSharpCode.Decompiler/IL/BlockBuilder.cs

@ -175,6 +175,12 @@ namespace ICSharpCode.Decompiler.IL @@ -175,6 +175,12 @@ namespace ICSharpCode.Decompiler.IL
cancellationToken.ThrowIfCancellationRequested();
Debug.Assert(branch.TargetBlock == null);
branch.TargetBlock = FindBranchTarget(branch.TargetILOffset);
if (branch.TargetBlock == null) {
branch.ReplaceWith(new InvalidBranch("Could not find block for branch target "
+ Disassembler.DisassemblerHelpers.OffsetToString(branch.TargetILOffset)) {
ILRange = branch.ILRange
});
}
break;
case Leave leave:
// ret (in void method) = leave(mainContainer)
@ -210,7 +216,7 @@ namespace ICSharpCode.Decompiler.IL @@ -210,7 +216,7 @@ namespace ICSharpCode.Decompiler.IL
return block;
}
}
throw new InvalidOperationException("Could not find block for branch target");
return null;
}
}
}

Loading…
Cancel
Save