Re: [PATCH 01/23] contrib/coccinnelle: add equals-null.cocci

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 30/04/2022 05:13, Elia Pinto wrote:
> Add a coccinelle semantic patch necessary to reinforce the git coding style
> guideline:
>
> "Do not explicitly compute an integral value with constant 0 or '\ 0', or a

s/compute/compare/
> pointer value with constant NULL."

If this gets re-rolled, perhaps include a simple example for those who
don't immediately understand that quoted sentence. It will also help
decode the coccinelle script

so:     `if (ptr == NULL)` becomes `if (!ptr)`  etc.

--
Philip
>
> Signed-off-by: Elia Pinto <gitter.spiros@xxxxxxxxx>
> ---
>  contrib/coccinelle/equals-null.cocci | 30 ++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
>  create mode 100644 contrib/coccinelle/equals-null.cocci
>
> diff --git a/contrib/coccinelle/equals-null.cocci b/contrib/coccinelle/equals-null.cocci
> new file mode 100644
> index 0000000000..92c7054013
> --- /dev/null
> +++ b/contrib/coccinelle/equals-null.cocci
> @@ -0,0 +1,30 @@
> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> +@@
> +expression e;
> +statement s;
> +@@
> +if (
> +(
> +!e
> +|
> +- e == NULL
> ++ !e
> +)
> +   )
> +   {...}
> +else s
> +
> +@@
> +expression e;
> +statement s;
> +@@
> +if (
> +(
> +e
> +|
> +- e != NULL
> ++ e
> +)
> +   )
> +   {...}
> +else s




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux