lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:	Thu, 29 Oct 2009 08:31:11 -0700 (PDT)
From:	Linus Torvalds <torvalds@...ux-foundation.org>
To:	David Howells <dhowells@...hat.com>
cc:	akpm@...ux-foundation.org, linux-cachefs@...hat.com,
	linux-kernel@...r.kernel.org, Roel Kluin <roel.kluin@...il.com>
Subject: Re: [PATCH] CacheFiles: Cleanup redundant tests on unsigned



On Mon, 26 Oct 2009, David Howells wrote:
>
> From: Roel Kluin <roel.kluin@...il.com>
> 
> The variables are unsigned so the test `>= 0' is always true,
> the `< 0' test always fails. The other part of
> the test catches wrapped values.

This is an excellent example of why I think that some gcc warnings are 
pure and utter sh*t, and why just blindly trying to avoid them then leads 
to worse code.

> -	if (datalen < 0 || datalen > PAGE_SIZE - 1)
> +	if (datalen > PAGE_SIZE - 1)
> -	if (fstop < 0 || fstop >= cache->fcull_percent)
> +	if (fstop >= cache->fcull_percent)
> -	if (bstop < 0 || bstop >= cache->bcull_percent)
> +	if (bstop >= cache->bcull_percent)

You've now actively made the code more fragile, only to avoid a warning.

The old code was clearly correct. The new code subtle depends on the type 
of comparison. 

I _hate_ those idiotic warnings, and in this case the "warning-free" code 
is actively worse than the original.

A smart compiler would see that it's a range check, and one that could 
have been done as an unsigned comparison (well, for the constant compare 
case) regardless of the type of the variable being tested. So a _smart_ 
compiler wouldn't complain, but it might use the signedness information to 
silently simplify the comparison.

A _stupid_ compiler complains, and thus forces people to either ignore the 
warning, or make the code worse.

Which one would you prefer?

		Linus
--
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

Powered by Openwall GNU/*/Linux Powered by OpenVZ