From: Julia Lawall <julia.lawall@lip6.fr>
To: Andrzej Hajda <a.hajda@samsung.com>
Cc: julia.lawall@lip6.fr, Gilles.Muller@lip6.fr,
nicolas.palix@imag.fr, mmarek@suse.com, cocci@systeme.lip6.fr,
joe@perches.com, linux-kernel@vger.kernel.org,
b.zolnierkie@samsung.com
Subject: Re: [PATCH v2] coccinelle: tests: unsigned value cannot be lesser than zero
Date: Wed, 16 Sep 2015 15:33:37 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.10.1509161533250.2429@hadrien> (raw)
In-Reply-To: <1442409749-32700-1-git-send-email-a.hajda@samsung.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
On Wed, 16 Sep 2015, Andrzej Hajda wrote:
> Code comparing unsigned variables with zero using operators < or >= does not
> make sense. It is always false or true, respectively. However, its presence
> often indicates bugs in the code.
> gcc can detect it also using -Wtype-limits switch, but it warns also in correct
> cases, making too much noise.
>
> Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
> ---
> v2: added --all-includes option
>
> As we discussed earlier I have dropped idea of adding v <= 0 as it is widely
> used in checking ranges, counters, quantities.
>
> Regards
> Andrzej
> ---
> .../tests/unsigned_lesser_than_zero.cocci | 37 ++++++++++++++++++++++
> 1 file changed, 37 insertions(+)
> create mode 100644 scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci
>
> diff --git a/scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci b/scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci
> new file mode 100644
> index 0000000..eab6d8c
> --- /dev/null
> +++ b/scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci
> @@ -0,0 +1,37 @@
> +/// Unsigned variables cannot be lesser than zero. Presence of such checks
> +/// can indicate incorrect variable type or just unnecessary code.
> +///
> +// Confidence: High
> +// Copyright: (C) 2015 Andrzej Hajda, Samsung Electronics Co., Ltd. GPLv2.
> +// URL: http://coccinelle.lip6.fr/
> +// Options: --include-headers --all-includes
> +
> +virtual context
> +virtual org
> +virtual report
> +
> +@r depends on context || org || report@
> +position p;
> +typedef u8, u16, u32, u64;
> +{unsigned char, unsigned short int, unsigned int, unsigned long, unsigned long long, size_t, u8, u16, u32, u64} v;
> +@@
> +
> +(
> +*v@p < 0
> +|
> +*v@p >= 0
> +)
> +
> +@script:python depends on org@
> +p << r.p;
> +@@
> +
> +msg = "WARNING: Unsigned value cannot be lesser than zero"
> +coccilib.org.print_todo(p[0], msg)
> +
> +@script:python depends on report@
> +p << r.p;
> +@@
> +
> +msg = "WARNING: Unsigned value cannot be lesser than zero"
> +coccilib.report.print_report(p[0], msg)
> --
> 1.9.1
>
>
next prev parent reply other threads:[~2015-09-16 13:33 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-15 9:27 [PATCH] " Andrzej Hajda
2015-09-15 13:01 ` SF Markus Elfring
2015-09-15 13:07 ` Julia Lawall
2015-09-15 13:16 ` SF Markus Elfring
2015-09-15 13:31 ` Julia Lawall
2015-09-15 13:51 ` Andrzej Hajda
2015-09-15 13:57 ` Julia Lawall
2015-09-16 9:11 ` Andrzej Hajda
2015-09-16 9:25 ` Julia Lawall
2015-09-16 13:22 ` [PATCH v2] " Andrzej Hajda
2015-09-16 13:33 ` Julia Lawall [this message]
2015-09-16 18:56 ` SF Markus Elfring
2015-09-15 13:42 ` [PATCH] " Andrzej Hajda
2015-09-15 14:36 ` SF Markus Elfring
2015-09-15 14:43 ` [Cocci] " Julia Lawall
2015-09-15 14:53 ` SF Markus Elfring
2015-09-18 5:35 ` Julia Lawall
2015-09-21 10:37 ` [PATCH v3] " Andrzej Hajda
2015-09-21 13:02 ` SF Markus Elfring
2015-09-21 13:34 ` Andrzej Hajda
2015-09-21 14:06 ` SF Markus Elfring
2015-09-22 15:27 ` SF Markus Elfring
2015-09-23 7:34 ` Andrzej Hajda
2015-09-23 15:17 ` SF Markus Elfring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.10.1509161533250.2429@hadrien \
--to=julia.lawall@lip6.fr \
--cc=Gilles.Muller@lip6.fr \
--cc=a.hajda@samsung.com \
--cc=b.zolnierkie@samsung.com \
--cc=cocci@systeme.lip6.fr \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mmarek@suse.com \
--cc=nicolas.palix@imag.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®