Home

Crashing LinqPad with a stack overflow

The following code will cause a stack overflow.

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

  • You're getting a stack overflow because you've defined your property recursively.

    Here's what it should look like:
    
    List<byte> _thing;
    public List<byte> thing
    {
    	get
    	{
    		return _thing;
    	}
    	set
    	{
    		_thing = crashBurn (value);
    	}
    }
    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.
  • Thanks for the response Joe! sorry I wasnt clearer; The post was meant to outline that a simple coding error, such as that outlined above, can crash LinqPad.
  • Most coding errors cannot crash LINQPad.

    A StackOverflowException is unusual in that it's impossible to catch. Try it and see.
Sign In or Register to comment.