[Cocci] Remove unnecessary null pointer checks?

Julia Lawall julia.lawall at lip6.fr
Mon Feb 24 07:00:55 CET 2014


On Sun, 23 Feb 2014, SF Markus Elfring wrote:

> > But I think that a switch is highly improbable for making such a test,
> > so you could just drop it.
> 
> I have got another idea for a bit of fine-tuning. I got the impression from the
> manual that the SmPL syntax element "singleton" might be applicable.
> 
> elfring at Sonne:~/Projekte/Coccinelle/janitor> LINE='-----' && echo $LINE &&
> PAT=list_input_parameter_validation2.cocci && cat $PAT && echo $LINE &&
> SP=/usr/local/bin/spatch && $SP --version && $SP --sp-file $PAT
> /usr/src/linux-stable/fs/btrfs/extent_map.c

Please don't put all of this noise in your messages.  The only thing that 
is interesting is the file on which you have run Coccinelle.

> -----
> 
> 
> @initialize:python@
> @@
> import sys
> result = []
> mark = ['"', '', '"']
> delimiter = '|'
> 
> def store_positions(fun, typ, point, places):
>     """Add source code positions to an internal list."""
>     for place in places:
>         fields = []
>         fields.append(fun)
> 
>         mark[1] = typ
>         fields.append(''.join(mark))
> 
>         fields.append(point)
> 
>         mark[1] = place.file.replace('"', '""')
>         fields.append(''.join(mark))
> 
>         fields.append(place.line)
>         fields.append(str(int(place.column) + 1))
>         result.append(delimiter.join(fields))
> 
> @safety_check@
> identifier work, input;
> type data_type;
> position pos;
> statement is, es;
> @@
>  void work at pos(...,data_type input,...)
>  {
>   ...
> ( if (!input) return;
> | if (input) is
> ? else es
>   ;

There is no need to put the ? else es.  If you put if (intput) is else es 
then an isomorphism will consider the case where else es is not there.

Also, the semicolon after is/es does not look right.  Notmally one does 
not put an extra semicolon after an if.

julia

> )
>   ...
>  }
> 
> @script:python collection depends on safety_check@
> typ << safety_check.data_type;
> fun << safety_check.work;
> point << safety_check.input;
> places << safety_check.pos;
> @@
> store_positions(fun, typ, point, places)
> 
> @finalize:python@
> @@
> if result:
>    result.insert(0, delimiter.join(("function", '"data type"', '"parameter"',
> '"source file"', "line", "column")))
>    print("\r\n".join(result))
> else:
>    sys.stderr.write("No result for this analysis!\n")
> -----
> spatch version 1.0.0-rc20 with Python support and with PCRE support
> init_defs_builtins: /usr/local/share/coccinelle/standard.h
> warning: incompatible arity found on line 36
> ?safety_check:es
> Fatal error: exception Failure("get_before_e: not supported")
> 
> 
> Can this situation be improved?
> 
> Regards,
> Markus
> 
> 


More information about the Cocci mailing list