Browse Source

Fix #855 - ArgumentOutOfRangeException in TransformCollectionAndObjectInitializers.DoTransform

pull/863/head 3.0-Preview1
Siegfried Pammer 8 years ago
parent
commit
f267a7875e
  1. 30
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/InitializerTests.cs
  2. 2
      ICSharpCode.Decompiler/IL/Transforms/LockTransform.cs
  3. 4
      ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs

30
ICSharpCode.Decompiler.Tests/TestCases/Correctness/InitializerTests.cs

@ -1015,5 +1015,35 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -1015,5 +1015,35 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
}
};
}
class Issue855
{
class Data
{
public object Obj;
}
class Items
{
public void SetItem(int i, object item) { }
}
object Item(string s, Data d)
{
return new object();
}
void Test()
{
Items items = null;
int num = 0;
for (int i = 0; i < 2; i++) {
if (num < 10)
items.SetItem(num, Item(string.Empty, new Data { Obj = null }));
}
}
}
}
}

2
ICSharpCode.Decompiler/IL/Transforms/LockTransform.cs

@ -22,7 +22,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -22,7 +22,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
// This happens in some cases:
// Use correct index after transformation.
if (i >= block.Instructions.Count)
i = block.Instructions.Count - 1;
i = block.Instructions.Count;
}
}

4
ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs

@ -36,6 +36,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -36,6 +36,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms
for (int i = block.Instructions.Count - 1; i >= 0; i--)
{
DoTransform(block, i);
// This happens in some cases:
// Use correct index after transformation.
if (i >= block.Instructions.Count)
i = block.Instructions.Count;
}
}

Loading…
Cancel
Save