Browse Source

Fix #959: Crash in CSharp.StatementBuilder.TranslateSwitch (due to empty sequence)

pull/925/merge
Siegfried Pammer 8 years ago
parent
commit
2c68d99336
  1. 2
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  2. 6
      ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs
  3. 12
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue959.cs
  4. 36
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue959.il
  5. 2
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

2
ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

@ -59,6 +59,7 @@ @@ -59,6 +59,7 @@
<ItemGroup>
<Compile Include="DataFlowTest.cs" />
<Compile Include="TestCases\Correctness\LINQRaytracer.cs" />
<Compile Include="TestCases\ILPretty\Issue959.cs" />
<None Include="TestCases\ILPretty\FSharpLoops_Debug.cs" />
<None Include="TestCases\ILPretty\FSharpLoops_Release.cs" />
<Compile Include="TestCases\Pretty\DelegateConstruction.cs" />
@ -79,6 +80,7 @@ @@ -79,6 +80,7 @@
<Compile Include="TestCases\Pretty\FixProxyCalls.cs" />
<Compile Include="TestCases\Pretty\UnsafeCode.cs" />
<Compile Include="TestCases\Pretty\InitializerTests.cs" />
<None Include="TestCases\ILPretty\Issue959.il" />
<None Include="TestCases\ILPretty\Issue646.cs" />
<Compile Include="TestCases\Pretty\Async.cs" />
<Compile Include="TestCases\Pretty\CheckedUnchecked.cs" />

6
ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs

@ -42,6 +42,12 @@ namespace ICSharpCode.Decompiler.Tests @@ -42,6 +42,12 @@ namespace ICSharpCode.Decompiler.Tests
Run();
}
[Test]
public void Issue959()
{
Run();
}
[Test]
public void FSharpUsing_Debug()
{

12
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue959.cs

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty
{
internal class Issue959
{
public void Test(bool arg)
{
switch (arg) {
}
}
}
}

36
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue959.il

@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
// Metadata version: v4.0.30319
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly ConsoleApp11
{
.ver 1:0:0:0
}
.module ConsoleApp11.exe
// MVID: {B973FCD6-A9C4-48A9-8291-26DDC248E208}
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00020003 // ILONLY 32BITPREFERRED
// Image base: 0x000001C4B6C90000
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue959
extends [mscorlib]System.Object
{
.method public hidebysig instance void Test(
bool arg
) cil managed
{
// Code size 18 (0x12)
.maxstack 8
IL_0000: ldarg.1
IL_0001: brfalse IL_000b
IL_0006: br IL_0011
IL_000b: ldarg.1
IL_000c: brtrue IL_0011
IL_0011: ret
} // end of method Program::Test
}

2
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -186,7 +186,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -186,7 +186,7 @@ namespace ICSharpCode.Decompiler.CSharp
break;
}
}
if (switchContainer != null) {
if (switchContainer != null && stmt.SwitchSections.Count > 0) {
// Translate any remaining blocks:
var lastSectionStatements = stmt.SwitchSections.Last().Statements;
foreach (var block in switchContainer.Blocks.Skip(1)) {

Loading…
Cancel
Save