return string from inside if block => Segmentation Fault: 11

Kapps via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 1 10:06:27 PDT 2015


On Monday, 1 June 2015 at 16:52:30 UTC, Robert M. Münch wrote:
> I'm a bit confused... I have the following class:
>
> class foo : superFoo {
> aFoo spec;
> aFoo lvars;
> aFoo bdy;
>
>  override string toString(){
>    if(spec.isEmpty() && lvars.isEmpty()){
>      return "does spec";
>    }
>
>    if(lvars.isEmpty()){
>      return "funct spec";
>    }
>
>    return "function spec";
>  }
> }
>
> The thing is, as soon as one if the IFs is true and the return 
> statement is executed I get a seg-fault: 11
>
> If I comment the IFs it works. But I can't see any differences 
> in returning from inside the if vs. the return at the end of 
> the function.
>
> Any idea?

Chances are very good that it's the code within the if statement, 
classes are null by default, you're checking if null isEmpty, 
thus getting a segfault.


More information about the Digitalmars-d-learn mailing list