Browse Source

Fix #2655: TranslateArrayInitializer crashes with out of order array init

pull/2679/head
Siegfried Pammer 3 years ago
parent
commit
6a3bb2bbf1
  1. 9
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs
  2. 2
      ICSharpCode.Decompiler/IL/Transforms/TransformArrayInitializers.cs

9
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs

@ -677,6 +677,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests @@ -677,6 +677,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
X(Y(), array);
}
public int[] IndicesInWrongOrderConstantsFull()
{
int[] array = new int[3];
array[0] = 0;
array[2] = 1;
array[1] = 2;
return array;
}
public static byte[] ReverseInitializer(int i)
{
byte[] array = new byte[4];

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

@ -440,7 +440,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -440,7 +440,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
for (int k = nextMinimumIndex.Length - 1; k >= 0; k--)
{
nextMinimumIndex[k]++;
if (nextMinimumIndex[k] < arrayLength[k])
if (nextMinimumIndex[k] < arrayLength[k] || k == 0)
break;
nextMinimumIndex[k] = 0;
}

Loading…
Cancel
Save