From d9952a7e107b0c3026ba6975de4b62bf6d3c8148 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 15 Feb 2019 16:36:10 +0100 Subject: [PATCH] #1388: Fix ArgumentOutOfRangeException in AsyncAwaitDecompiler.AnalyzeAwaitBlock. --- .../IL/ControlFlow/AsyncAwaitDecompiler.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs b/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs index 53bb9b97b1..e9ad731530 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs @@ -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)) { @@ -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.