On Mon, 21 Mar 2011, Anders Wegge Keller wrote:

> Julia Lawall <[email protected]> writes:
> 
> > On Mon, 21 Mar 2011, Anders Wegge Keller wrote:
> >
> >> Hi,
> >> 
> >>  I've tried going over our codebase with the following script, to find
> >> places where memory allocations are not checked before usage:
> >> 
> >> @@
> >> identifier ptr, fld;
> >> @@
> >> * ptr = dMemAlloc(...)
> >> 
> >>  ... when != (ptr != NULL)
> >> 
> >> * ptr->fld
> >
> > Try:
> >
> > @@
> > identifier ptr, fld;
> > @@
> > (
> >   (ptr = dMemAlloc(...)) == NULL
> > |
> > * ptr = dMemAlloc(...)
> >
> >  ... when != (ptr != NULL)
> >
> > * ptr->fld
> > )
> >
> 
>  I see the intention, but unfortunately it doesn't parse:
> 
> init_defs_builtins: /usr//share/coccinelle/standard.h
> 89 92
> Fatal error: exception Failure("minus: parse error: 
>  = File "/pro/awj/Linux/Coccinelle/Unchecked_dMemAlloc.cocci", line 9, column 
> 1,  charpos = 89
>     around = '...', whole content =  ... when != (ptr != NULL)
> ")

OK.  It's a parser ambiguity problem.  If any branch of a disjunction can 
represent a statement the first one has to.  Here the first branch 
represents a single expression.  You could make the first branch be 
instead:

if ((ptr = dMemAlloc(...)) == NULL || ...) S1 else S2

where S1 and S2 are statement metavariables.

julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to