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

Andy Grove andy.grove at codefutures.com
Tue Feb 3 09:49:47 PST 2009


Jim,

Thanks. I'll modify the grammar and that will work fine with Java or C. It
would be nice if the C generator could init the member variables of the
struct so that the generated NULL check doesn't cause a seg fault. Just a
nice to have though.

Thanks again.

Andy.

On Tue, Feb 3, 2009 at 10:18 AM, Jim Idle <jimi at temporal-wave.com> wrote:

> Andy Grove wrote:
> > Hi Jim,
> >
> > I have further info on this now. Here's the relevant portion of
> > grammar. The "a1" is optional but is always referenced in the action.
> > This works fine when generating Java code from the grammar (the action
> > gets passed a NULL parameter for "a1"). The generated C code has a
> > NULL check for a1.start just like the generated Java code does, but
> > because a1.start is never initialized in C it blows up.
> >
> > | e = expression
> >             ( a1 = alias1  )?
> >         { sse.addSelectItem($e.text, $a1.text); }
> >
> > Would it be possible to modify the generator to initialize these
> > variables to sensible defaults e.g. NULL for compatibility with the
> > Java generator?
> >
> > Alternatively, how could I modify the grammar to check if a1 is NULL
> > or not?
>
> Yes, well we could argue that this isn't quite Kosher use, but I was
> pretty sure that the value should be initialized. The thing is that this
> is a structure return, so the structure is allocated but I don't really
> know about the elements within the structure, that is just part of the
> codegen. However this should work better:
>
> | e = expression
>            ( a1 = alias1
>                   { sse.addSelectItem($e.text, $a1.text); }
>              |     { sse.addSelectItem($e.text, NULL); }
>            )
> ...
>
>
> Jim
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090203/55dd9d9b/attachment.html 


More information about the antlr-interest mailing list