[antlr-interest] Error in generated C code (struct referenced without being initialized)

Jim Idle jimi at temporal-wave.com
Tue Feb 3 08:50:12 PST 2009


Andy Grove wrote:
> Hi,
>
> In my generated parse, a variable "a1" is declared thus:
>
>     DbsMySQL_CPPParser_alias1_return a1;
>
> Under certain conditions the variable gets initialized by calling a 
> method:
>
> a1=alias(ctx);
>
> However, when parsing my input, the variable is not getting 
> initialized but it *is* getting referenced in the following 
> expression, causing a seg fault:
>
> (a1.start != NULL ? STRSTREAM->toStringTT(STRSTREAM, a1.start, 
> a1.stop) : NULL )
>
> Because a1 is never initialized, a1.start refers to non null value. If 
> I add a1.start = NULL after a1 is declared then the seg fault is fixed.
>
> Is this a known issue? Do I need to specify special options when 
> generating the code to make sure structs get initialized?
I have never known the initialization code not to be initialized - can 
you provide a grammar sample that shows this? It is usually grammar 
samples rather than the generated code that i need to reproduce things :-)

Jim


More information about the antlr-interest mailing list