Browse Source

Fix #1131: Add a few safety null checks in TransformForeachOnMultiDimArray

pull/1143/head
Siegfried Pammer 7 years ago
parent
commit
504fe200b6
  1. 4
      ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs

4
ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs

@ -391,7 +391,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -391,7 +391,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
if (!m.Success) break;
if (upperBounds == null) {
collection = m.Get<IdentifierExpression>("collection").Single().GetILVariable();
if (!(collection.Type is Decompiler.TypeSystem.ArrayType arrayType))
if (!(collection?.Type is Decompiler.TypeSystem.ArrayType arrayType))
break;
upperBounds = new IL.ILVariable[arrayType.Dimensions];
} else {
@ -414,7 +414,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -414,7 +414,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
statementsToDelete.Add(stmt);
statementsToDelete.Add(stmt.GetNextStatement());
var itemVariable = foreachVariable.GetILVariable();
if (!itemVariable.IsSingleDefinition
if (itemVariable == null || !itemVariable.IsSingleDefinition
|| !upperBounds.All(ub => ub.IsSingleDefinition && ub.LoadCount == 1)
|| !lowerBounds.All(lb => lb.StoreCount == 2 && lb.LoadCount == 3 && lb.AddressCount == 0))
return null;

Loading…
Cancel
Save