Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1299338

Re: [PATCH v4] coccinelle: tests: unsigned value cannot be lesser than zero

From Andrzej Hajda <a.hajda@samsung.com>
Newsgroups linux.kernel
Subject Re: [PATCH v4] coccinelle: tests: unsigned value cannot be lesser than zero
Date 2015-12-30 13:40 +0100
Message-ID <qLocN-6Df-3@gated-at.bofh.it> (permalink)
References <qLmNH-5Po-3@gated-at.bofh.it> <qLn73-5Wu-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 12/30/2015 12:29 PM, Julia Lawall wrote:
> 
> 
> On Wed, 30 Dec 2015, Andrzej Hajda wrote:
> 
>> 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>
>> ---
>> 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
>> ---
>> Hi Julia,
>>
>> This version adds range check detection, as a result false positives are almost
>> fully eliminated. Most of kernel patches have been already sent and accepted,
>> but some new bugs appeared since then. I will prepare bugfixes soon.
>>
>> I have enountered one issue, the patch does not detect range check in
>> drivers/leds/leds-tca6507.c:716:
>>     if (ret != 0 || reg < 0 || reg >= NUM_LEDS)
>>
>> Simplified check, responsible for detectin range checks:
>> @@
>> expression v, c;
>> @@
>>
>> * (\( v < 0 \| v <= 0 \)) || (\( v >= c \| v > c \))
>>
>> Is it a bug or expected behavior? Maybe consequence of left-to-right associativity?
> 
> Yes, it would be an associativity problem.  Could you try with || ... 
> added to the right end of your pattern?  That should allow it to let the 
> disjunctions appear anywhere at top level, but I'm not sure to what extent 
> it works when the pattern already contains a disjunction.  You could also 
> try
> 
> A || ... || B || ...
> 

"A || ... || B" does the trick.

Regards
Andrzej

--
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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v4] coccinelle: tests: unsigned value cannot be lesser than zero Andrzej Hajda <a.hajda@samsung.com> - 2015-12-30 12:10 +0100
  Re: [PATCH v4] coccinelle: tests: unsigned value cannot be lesser  than zero Julia Lawall <julia.lawall@lip6.fr> - 2015-12-30 12:30 +0100
    Re: [PATCH v4] coccinelle: tests: unsigned value cannot be lesser than  zero Andrzej Hajda <a.hajda@samsung.com> - 2015-12-30 13:40 +0100
      [PATCH v5] coccinelle: tests: unsigned value cannot be lesser than zero Andrzej Hajda <a.hajda@samsung.com> - 2015-12-30 14:30 +0100
        Re: [PATCH v5] coccinelle: tests: unsigned value cannot be lesser  than zero Julia Lawall <julia.lawall@lip6.fr> - 2015-12-30 15:10 +0100

csiph-web