Browse Source

Fix #1075: NullReferenceException in StatementBuilder.TranslateSwitch

pull/1087/head
Siegfried Pammer 8 years ago
parent
commit
384111f0dd
  1. 5
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs
  2. 1
      ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs

5
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -112,7 +112,6 @@ namespace ICSharpCode.Decompiler.CSharp
SwitchStatement TranslateSwitch(BlockContainer switchContainer, SwitchInstruction inst)
{
Debug.Assert(switchContainer.EntryPoint.IncomingEdgeCount == 1);
var oldBreakTarget = breakTarget;
breakTarget = switchContainer; // 'break' within a switch would only leave the switch
var oldCaseLabelMapping = caseLabelMapping;
@ -159,7 +158,7 @@ namespace ICSharpCode.Decompiler.CSharp
switch (section.Body) {
case Branch br:
// we can only inline the block, if all branches are in the switchContainer.
if (br.TargetBlock.Parent == switchContainer && switchContainer.Descendants.OfType<Branch>().Where(b => b.TargetBlock == br.TargetBlock).All(b => BlockContainer.FindClosestSwitchContainer(b) == switchContainer))
if (br.TargetContainer == switchContainer && switchContainer.Descendants.OfType<Branch>().Where(b => b.TargetBlock == br.TargetBlock).All(b => BlockContainer.FindClosestSwitchContainer(b) == switchContainer))
caseLabelMapping.Add(br.TargetBlock, firstValueResolveResult);
break;
default:
@ -173,7 +172,7 @@ namespace ICSharpCode.Decompiler.CSharp
switch (section.Body) {
case Branch br:
// we can only inline the block, if all branches are in the switchContainer.
if (br.TargetBlock.Parent == switchContainer && switchContainer.Descendants.OfType<Branch>().Where(b => b.TargetBlock == br.TargetBlock).All(b => BlockContainer.FindClosestSwitchContainer(b) == switchContainer))
if (br.TargetContainer == switchContainer && switchContainer.Descendants.OfType<Branch>().Where(b => b.TargetBlock == br.TargetBlock).All(b => BlockContainer.FindClosestSwitchContainer(b) == switchContainer))
ConvertSwitchSectionBody(astSection, br.TargetBlock);
else
ConvertSwitchSectionBody(astSection, section.Body);

1
ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs

@ -193,6 +193,7 @@ namespace ICSharpCode.Decompiler.IL
case ContainerKind.Switch:
Debug.Assert(EntryPoint.Instructions.Count == 1);
Debug.Assert(EntryPoint.Instructions[0] is SwitchInstruction);
Debug.Assert(EntryPoint.IncomingEdgeCount == 1);
break;
case ContainerKind.While:
Debug.Assert(EntryPoint.IncomingEdgeCount > 1);

Loading…
Cancel
Save