[Cocci] Remove unnecessary null pointer checks?

Julia Lawall julia.lawall at lip6.fr
Mon Feb 24 16:19:22 CET 2014


On Mon, 24 Feb 2014, SF Markus Elfring wrote:

> > There is no need to put the ? else es.
>
> I get the following result for the adjusted search pattern.
>
>  void work at pos(...,data_type input,...)
>  {
>   ...
> ( if (!input) return;
> | if (input) is else es
> )
>   ...
>  }
>
>
> elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch --sp-file
> list_input_parameter_validation2.cocci /usr/src/linux-stable/arch/um/kernel/sysrq.c
> ...
> function|"data type"|"parameter"|"source file"|line|column
> show_stack|"unsigned long
> *"|stack|"/usr/src/linux-stable/arch/um/kernel/sysrq.c"|67|6
>
>
> This example does not fit to my expectation because it seems that the function
> implementation does not refer to the passed values.
> Do you get any idea for this potential mismatch?

I'm not sure, but I think it has to do with the fact that the entire
function is an if where both branches leave the function.  It seems to be
considering that to be error-handling code.  It does not require to find
the complete pattern on execution paths that correspond to error-handling
code.  So it doesn't require to find the pattern at all.

In your case, I think you want to be completely sure that regardless of
the execution path chosen, the test is performed.  So you should put when
string after the first ... (ie the one after the first { ).

julia


More information about the Cocci mailing list