Skip to content

Commit

Permalink
Fix #855 - ArgumentOutOfRangeException in TransformCollectionAndObjec…
Browse files Browse the repository at this point in the history
…tInitializers.DoTransform
  • Loading branch information
siegfriedpammer committed Sep 19, 2017
1 parent 8285d01 commit f267a78
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1015,5 +1015,35 @@ public static void Bug270_NestedInitialisers()
}
};
}

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 changes: 1 addition & 1 deletion ICSharpCode.Decompiler/IL/Transforms/LockTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void IBlockTransform.Run(Block block, BlockTransformContext context)
// This happens in some cases:
// Use correct index after transformation.
if (i >= block.Instructions.Count)
i = block.Instructions.Count - 1;
i = block.Instructions.Count;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ void IBlockTransform.Run(Block block, BlockTransformContext context)
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;
}
}

Expand Down

0 comments on commit f267a78

Please sign in to comment.