Skip to content

Commit

Permalink
#1388: Fix ArgumentOutOfRangeException in AsyncAwaitDecompiler.Analyz…
Browse files Browse the repository at this point in the history
…eAwaitBlock.
  • Loading branch information
siegfriedpammer committed Feb 15, 2019
1 parent b7fc830 commit d9952a7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ bool AnalyzeAwaitBlock(Block block, out ILVariable awaiter, out IField awaiterFi
awaiterField = null;
state = 0;
int pos = block.Instructions.Count - 2;
if (doFinallyBodies != null && block.Instructions[pos] is StLoc storeDoFinallyBodies) {
if (pos >= 0 && doFinallyBodies != null && block.Instructions[pos] is StLoc storeDoFinallyBodies) {
if (!(storeDoFinallyBodies.Variable.Kind == VariableKind.Local
&& storeDoFinallyBodies.Variable.Type.IsKnownType(KnownTypeCode.Boolean)
&& storeDoFinallyBodies.Variable.Index == doFinallyBodies.Index)) {
Expand All @@ -600,9 +600,9 @@ bool AnalyzeAwaitBlock(Block block, out ILVariable awaiter, out IField awaiterFi
pos--;
}

if (MatchCall(block.Instructions[pos], "AwaitUnsafeOnCompleted", out var callArgs)) {
if (pos >= 0 && MatchCall(block.Instructions[pos], "AwaitUnsafeOnCompleted", out var callArgs)) {
// call AwaitUnsafeOnCompleted(ldflda <>t__builder(ldloc this), ldloca awaiter, ldloc this)
} else if (MatchCall(block.Instructions[pos], "AwaitOnCompleted", out callArgs)) {
} else if (pos >= 0 && MatchCall(block.Instructions[pos], "AwaitOnCompleted", out callArgs)) {
// call AwaitOnCompleted(ldflda <>t__builder(ldloc this), ldloca awaiter, ldloc this)
// The C# compiler emits the non-unsafe call when the awaiter does not implement
// ICriticalNotifyCompletion.
Expand Down

0 comments on commit d9952a7

Please sign in to comment.