[Mono-list] Segmentation fault / StackOverflowException not thrown

Michael Levy mlevy@wardium.homeip.net
Fri, 11 Jul 2003 22:29:15 +0200


--0F1p//8PRICkK4MW
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hello,
	I am fairly new to C# (and mono) but I think that I may have found
a potential bug. I have attached a short peice of (silly) code which
shows the problem. The code basically causes a method (or property, depending
on what you have un-commented) to recursivly call itsel until it blows the
stack. I would expect that this sort of pathological recursion should generate 
a StackoverflowException when executed, but it simpley causes a Segmentation fault.
I have not been able to confirm this behaviour on Windows. I am using the lates
release of mono (0.25).

Mike Levy

--0F1p//8PRICkK4MW
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="stack_overflow.cs"

// Example of StackOverflowException not thrown when faced with
// pathological recursion 

public class C
{
  int var;
  
  public int P
  {
    // Note the the recursion we are returning the property itself!
    get { return P; }
  }

  public int M()
  {
    // Note the recursive call
    return M();
  }
}

public class Driver
{
  public static void Main()
  {
    C i = new C();
    
    try 
    {
      // Either of the following lines causes a SegV (mono 0.25)
      //System.Console.WriteLine("var is {0}", i.P);
      System.Console.WriteLine("var is {0}", i.M());
    } 
    catch 
    {
      // We actually never get here because an exception isn't thrown
      // but a StackOverFlowException should have been
      System.Console.WriteLine("Caught");
    }
  }
}

--0F1p//8PRICkK4MW--