From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752918AbbIPNdk (ORCPT ); Wed, 16 Sep 2015 09:33:40 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:3938 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752424AbbIPNdj (ORCPT ); Wed, 16 Sep 2015 09:33:39 -0400 X-IronPort-AV: E=Sophos;i="5.17,539,1437429600"; d="scan'208";a="177886044" Date: Wed, 16 Sep 2015 15:33:37 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Andrzej Hajda 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 In-Reply-To: <1442409749-32700-1-git-send-email-a.hajda@samsung.com> Message-ID: References: <1442409749-32700-1-git-send-email-a.hajda@samsung.com> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Acked-by: Julia Lawall 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 > --- > 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 > >