Crashing LinqPad with a stack overflow
The following code will cause a stack overflow.
SLR-
void Main()
{
byte[] array = new byte[166];
var nodeList = splitPayload(array);
List<object> payload = new List<object>();
nodeList.ForEach(delegate(byte[] block)
{
payload.Add(processBlocks(block));
});
payload.Dump();
}
private static List<byte[]> splitPayload(byte[] array)
{
List<byte[]> result = new List<byte[]>();
for (int i = 1; i < array.Length; i += 55)
{
byte[] buffer = new byte[55];
Buffer.BlockCopy(array, i, buffer, 0, 55);
result.Add(buffer);
}
return result;
}
private static Some processBlocks(byte[] node)
{
List<byte> nodeData = new List<byte>();
nodeData = node.ToList();
Some n = new Some();
n.thing = nodeData.GetRange(0,4);
return n;
}
public class Some
{
public List<byte> thing
{
get
{
return thing;
}
set
{
thing = crashBurn(value);
}
}
public List<byte> crashBurn(List<byte> element)
{
return element;
}
}
SLR-
Comments
Here's what it should look like: Check out the free examples in LINQPad from C# 5.0 in a Nutshell. Go to samples | Download More Samples, choose C# 5 in a Nutshell, and do a search-all for properties. This should get you started.
A StackOverflowException is unusual in that it's impossible to catch. Try it and see.