On Fri, 24 May 2019, Timur Tabi wrote:
> On Fri, May 24, 2019 at 2:48 PM Julia Lawall <[email protected]> wrote:
> >
> >
> >
> > On Fri, 24 May 2019, Timur Tabi wrote:
> >
> > > I'm working on a new script that needs to add a NULL-pointer check if
> > > one does not already exist. For example:
> > >
> > > x = (MYTYPE)MACRO(params);
> > >
> > > should become
> > >
> > > x = (MYTYPE)MACRO(params);
> > > if (!x) {
> > > do_something;
> > > }
> > >
> > > My problem is that I want coccinelle to add the if-check only if it
> > > doesn't already exist. So currently I have this:
> > >
> > > @@
> > > type T;
> > > expression x;
> > > @@
> > > x = (T)MACRO(...);
> > > +if (x == NULL)
> > > +{
> > > + status = ERROR;
> > > + goto exit;
> > > +}
> > >
> > > How do I make sure that these lines are not added if they already
> > > exist? I need to check for "if (x == NULL)" and "if (!x)" variants.
> >
> > (
> > A
> > B
> > |
> > A
> > +B
> > )
>
> I can't quite get this to work:
>
> func(...) {
> <+...
> x = (T)MACRO(...);
> (
> if (x == NULL)
You can't just put the header of an if. You have to put the whole thing:
if (x == NULL) S1 else S2
julia
> |
> +if (x == NULL)
> +{
> + goto label;
> +}
> )
> ...+>
> }
>
> This gives me:
> minus: parse error:
> File "/home/ttabi/boardobj.cocci", line 12, column 0, charpos = 157
> around = '|',
> whole content = |
>
> Line 12 is the |
>
>
>
> >
> > Just put the == NULL variant. An isomorphism will take care of the !x
> > case.
> >
> > julia
> >
> >
> >
> >
> > > _______________________________________________
> > > Cocci mailing list
> > > [email protected]
> > > https://systeme.lip6.fr/mailman/listinfo/cocci
> > >
> > _______________________________________________
> > Cocci mailing list
> > [email protected]
> > https://systeme.lip6.fr/mailman/listinfo/cocci
>
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci