On Wed, 3 Nov 2010, Michael T wrote:

> 
> Hello,
> 
> I wanted to point out a couple of issues with your mini_null_ref2.cocci 
> example.
> The first is that it is lacking a test:
> 
>  --- mini_null_ref2-2.cocci    2010-11-03 22:33:39.059472002 +0100
> +++ mini_null_ref2.cocci    2010-11-03 22:35:16.529472002 +0100
> @@ -9,13 +9,14 @@
>  
>  @@
>  expression E,E1;
> -identifier f,f1,fld,fld1;
> +identifier f,fld,fld1;
>  statement S1,S2;
>  @@
>  
>  E->fld = f(...);
>  ... when != E = E1
>      when != E->fld1 = E1
> +    when != f1(&E)
>  if (
>  -   E
>  +   E->fld
> 
> although that should also allow and number of arguments to f1 before and 
> after &E,

Yes, this seems like a good idea.  You can instead write f1(...,&E,...) 
which allows &E to appear in any argument position.  I will make the 
change in the example on the web site.

> I just don't know the right coccinelle syntax.  The second point is that the 
> suggested
> fix is only one possible case - it may just be that someone is being too 
> careful and
> testing for NULL although it is not needed.  So the script should probably do 
> a
> printf rather than suggesting a correction.

Normally, Coccinelle produces a patch, unless you give the -in_place or -o 
option.  The user should then look at this patch and see if it is 
appropriate.  In this case, I think it is appropriate often enough that it 
is useful to have a patch already made, if one does want to apply it.  If 
it did a printf, one would have to make the adjustment manually, and could 
make a mistake.  On the other hand, if you prefer a printf, it is easy to 
change (the following generates emacs org mode):

@r@
type T;
expression E;
identifier i,fld,f1;
position p,p1;
@@

  T i...@p = E->fld;
      when != i
      when != f1(...,&E,...)
  if (e...@p1 == NULL) { ... return ...; }

@script:python@
p << r.p;
p1 << r.p1;
@@

cocci.print_main("bad declaration",p)
cocci.print_secs("bad test",p1)

There is no trace, though of what the change could be, although one could 
adjust the strings to give this information.

Thanks for the feedback.

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

Reply via email to