[Cocci] Remove unnecessary null pointer checks?

SF Markus Elfring elfring at users.sourceforge.net
Tue Feb 25 11:01:02 CET 2014


> This is not allowed.  Inside a disjunction you need to have complete terms.

Thanks for your information. I guess that another adjustment will fit to the
SmPL syntax then.

( if (input) is else es
| if (likely(input)) is else es
)


> I'm not sure to understand your goal.  If the code currently has:
> 
> if (x != NULL)
>    call(x);
> 
> then the developer does not want to execute any of the code within call if
> x is NULL.

Yes. - This is one of the use cases I am trying to improve. It depends on the
knowledge if something unwanted will happen if a null pointer (or zero) would be
passed. If it is documented for example that an implementation of the function
"call" checks the condition "!= NULL", I find the same check by the caller
redundant.


> If you just check that there is a NULL test on x somewhere within the definition
> of call, then that is not enough to ensure that nothing is executed within call.

Would you like to suggest any more fine-tuning?


> If you remove the NULL test, you could drastically change the behavior of the program.

I agree in principle.

But I would like to delete redundant checks from some source files.

Regards,
Markus


More information about the Cocci mailing list