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] [thread-next>] [day] [month] [year] [list]
Message-ID: <87txk5esce.fsf@rustcorp.com.au>
Date:	Mon, 08 Jul 2013 11:16:41 +0930
From:	Rusty Russell <rusty@...tcorp.com.au>
To:	Wedson Almeida Filho <wedsonaf@...il.com>,
	Tim Abbott <tabbott@...lice.com>
Cc:	linux-kernel@...r.kernel.org,
	Wedson Almeida Filho <wedsonaf@...il.com>
Subject: Re: [PATCH] lib: One less subtraction in binary search iterations.

Wedson Almeida Filho <wedsonaf@...il.com> writes:
> There is no functional change, but this change eliminates a subtraction that
> the compiler doesn't optimize out (as of gcc 4.7.3).
>
> Signed-off-by: Wedson Almeida Filho <wedsonaf@...il.com>
> ---
>  lib/bsearch.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/bsearch.c b/lib/bsearch.c
> index e33c179..3264146 100644
> --- a/lib/bsearch.c
> +++ b/lib/bsearch.c
> @@ -37,7 +37,7 @@ void *bsearch(const void *key, const void *base, size_t num, size_t size,
>  	int result;
>  
>  	while (start < end) {
> -		size_t mid = start + (end - start) / 2;
> +		size_t mid = (start + end) / 2;
>  
>  		result = cmp(key, base + mid * size);
>  		if (result < 0)
> -- 
> 1.7.9.5

Please add a comment about overflow instead?

Thanks,
Rusty.
--
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