[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <17571.1442842945@warthog.procyon.org.uk>
Date: Mon, 21 Sep 2015 14:42:25 +0100
From: David Howells <dhowells@...hat.com>
To: Andrzej Hajda <a.hajda@...sung.com>
Cc: dhowells@...hat.com, linux-kernel@...r.kernel.org,
linux-api@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
linux-cachefs@...hat.com, linux-clk@...r.kernel.org,
linux-crypto@...r.kernel.org, linux-fbdev@...r.kernel.org,
linux-input@...r.kernel.org, linux-leds@...r.kernel.org,
linux-media@...r.kernel.org, linux-mips@...ux-mips.org,
linux-mm@...ck.org, linux-omap@...r.kernel.org,
linux-rdma@...r.kernel.org, linux-serial@...r.kernel.org,
linux-sh@...r.kernel.org, linux-usb@...r.kernel.org,
linux-wireless@...r.kernel.org, lustre-devel@...ts.lustre.org
Subject: Re: [PATCH 00/38] Fixes related to incorrect usage of unsigned types
Andrzej Hajda <a.hajda@...sung.com> wrote:
> Semantic patch finds comparisons of types:
> unsigned < 0
> unsigned >= 0
> The former is always false, the latter is always true.
> Such comparisons are useless, so theoretically they could be
> safely removed, but their presence quite often indicates bugs.
Or someone has left them in because they don't matter and there's the
possibility that the type being tested might be or become signed under some
circumstances. If the comparison is useless, I'd expect the compiler to just
discard it - for such cases your patch is pointless.
If I have, for example:
unsigned x;
if (x == 0 || x > 27)
give_a_range_error();
I will write this as:
unsigned x;
if (x <= 0 || x > 27)
give_a_range_error();
because it that gives a way to handle x being changed to signed at some point
in the future for no cost. In which case, your changing the <= to an ==
"because the < part of the case is useless" is arguably wrong.
David
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists