lkml.org 
[lkml]   [2009]   [Nov]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 1/2] bsearch: avoid unneeded decrement arithmetic
Date
Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
---
lib/bsearch.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/bsearch.c b/lib/bsearch.c
index 2e70664..f71ac89 100644
--- a/lib/bsearch.c
+++ b/lib/bsearch.c
@@ -33,9 +33,9 @@
void *bsearch(const void *key, const void *base, size_t num, size_t size,
int (*cmp)(const void *key, const void *elt))
{
- int start = 0, end = num - 1, mid, result;
+ int start = 0, end = num, mid, result;

- while (start <= end) {
+ while (start < end) {
mid = (start + end) / 2;
result = cmp(key, base + mid * size);
if (result < 0)
--
1.6.5.2.153.g6e31f.dirty
--
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/

\
 
 \ /
  Last update: 2009-11-10 15:31    [W:0.034 / U:0.208 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site