Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1301556
| From | "Geyslan G. Bem" <geyslan@gmail.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v6] coccinelle: tests: unsigned value cannot be lesser than zero |
| Date | 2016-01-05 15:20 +0100 |
| Message-ID | <qNACS-3VY-13@gated-at.bofh.it> (permalink) |
| References | <qLpBT-7EZ-7@gated-at.bofh.it> <qN83U-op-13@gated-at.bofh.it> <qNznt-2S7-17@gated-at.bofh.it> <qNAjx-3vz-27@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
2016-01-05 10:49 GMT-03:00 Andrzej Hajda <a.hajda@samsung.com>: > On 01/05/2016 01:59 PM, Geyslan G. Bem wrote: >> Hello, >> >> 2016-01-04 4:45 GMT-03:00 Andrzej Hajda <a.hajda@samsung.com>: >>> Unsigned expressions cannot be lesser than zero. Presence of comparisons >>> 'unsigned (<|<=|>|>=) 0' often indicates a bug, usually wrong type of variable. >>> The patch beside finding such comparisons tries to eliminate false positives, >>> mainly by bypassing range checks. >>> >>> gcc can detect such comparisons 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> >>> --- >>> v6: improved range check detection (according to Julia suggestion) >>> v5: improved range check detection >>> v4: added range check detection, added full check in case value holds a result >>> of signed function >>> v3: added bool type >>> v2: added --all-includes option >>> --- >>> .../tests/unsigned_lesser_than_zero.cocci | 76 ++++++++++++++++++++++ >>> 1 file changed, 76 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..b9c7ed8 >>> --- /dev/null >>> +++ b/scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci >>> @@ -0,0 +1,76 @@ >>> +/// Unsigned expressions cannot be lesser than zero. Presence of >>> +/// comparisons 'unsigned (<|<=|>|>=) 0' often indicates a bug, >>> +/// usually wrong type of variable. >>> +/// >>> +/// To reduce number of false positives following tests have been added: >>> +/// - parts of range checks are skipped, eg. "if (u < 0 || u > 15) ...", >>> +/// developers prefer to keep such code, >>> +/// - comparisons "<= 0" and "> 0" are performed only on results of >>> +/// signed functions/macros, >> Why common unsigned comparisons with <= 0 are not being detected? I >> think that it misleads the code reading and induces further bugs. >> Just reading "var <= 0" infers that var can receive signed value. The >> be clear the comparison should be against zero only "var == 0" or >> depending of the context "!var". >> > > Many developers prefer to use "unsigned <= 0" comparison, as more > descriptive > and less fragile. See for example for the last phrase of Linus email[1]. > > [1]: http://permalink.gmane.org/gmane.linux.kernel/2054063 I got it. Tks. > > Regards > Andrzej > -- Regards, Geyslan G. Bem hackingbits.com -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v6] coccinelle: tests: unsigned value cannot be lesser than zero Andrzej Hajda <a.hajda@samsung.com> - 2016-01-04 08:50 +0100
Re: [PATCH v6] coccinelle: tests: unsigned value cannot be lesser than zero "Geyslan G. Bem" <geyslan@gmail.com> - 2016-01-05 14:00 +0100
Re: [PATCH v6] coccinelle: tests: unsigned value cannot be lesser than zero Julia Lawall <julia.lawall@lip6.fr> - 2016-01-05 14:10 +0100
Re: [PATCH v6] coccinelle: tests: unsigned value cannot be lesser than zero "Geyslan G. Bem" <geyslan@gmail.com> - 2016-01-05 15:20 +0100
Re: [PATCH v6] coccinelle: tests: unsigned value cannot be lesser than zero "Geyslan G. Bem" <geyslan@gmail.com> - 2016-01-05 17:50 +0100
Re: [PATCH v6] coccinelle: tests: unsigned value cannot be lesser than zero Andrzej Hajda <a.hajda@samsung.com> - 2016-01-05 15:00 +0100
Re: [PATCH v6] coccinelle: tests: unsigned value cannot be lesser than zero "Geyslan G. Bem" <geyslan@gmail.com> - 2016-01-05 15:20 +0100
Re: [PATCH v6] coccinelle: tests: unsigned value cannot be lesser than zero Julia Lawall <julia.lawall@lip6.fr> - 2016-01-05 15:20 +0100
Re: [PATCH v6] coccinelle: tests: unsigned value cannot be lesser than zero Andrzej Hajda <a.hajda@samsung.com> - 2016-01-05 15:30 +0100
[PATCH v7] coccinelle: tests: unsigned value cannot be lesser than zero Andrzej Hajda <a.hajda@samsung.com> - 2016-01-07 10:40 +0100
Re: [PATCH v7] coccinelle: tests: unsigned value cannot be lesser than zero Julia Lawall <julia.lawall@lip6.fr> - 2016-01-07 12:40 +0100
Re: [PATCH v7] coccinelle: tests: unsigned value cannot be lesser than zero Michal Marek <mmarek@suse.com> - 2016-01-07 15:40 +0100
csiph-web