Re: [PATCH 00/38] Fixes related to incorrect usage of unsigned types

From
David Howells <hidden>
Date
2015-09-21 13:42:40
Also in
linux-arm-kernel, linux-clk, linux-crypto, linux-fbdev, linux-input, linux-leds, linux-media, linux-mips, linux-mm, linux-omap, linux-rdma, linux-serial, linux-sh, linux-wireless, lkml
Reply to
Andrzej Hajda, 2015-09-21
Andrzej Hajda [off-list ref] 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-wireless" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Thread (6 messages) 6 messages, 4 authors, last reply 2015-12-11
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help