From: "André Goddard Rosa" <andre.goddard@gmail.com>
To: tabbott@ksplice.com, alan-jenkins@tuffmail.co.uk,
rusty@rustcorp.com.au, linux-kernel@vger.kernel.org
Cc: "André Goddard Rosa" <andre.goddard@gmail.com>
Subject: [PATCH v4 1/2] bsearch: avoid unneeded decrement arithmetic
Date: Tue, 10 Nov 2009 13:00:24 -0200 [thread overview]
Message-ID: <28b3abe6d9a03d4251c0b42a3505c8bc5f861e69.1257864802.git.andre.goddard@gmail.com> (raw)
In-Reply-To: <cover.1257864802.git.andre.goddard@gmail.com>
Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
---
lib/bsearch.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/bsearch.c b/lib/bsearch.c
index 2e70664..33cbba6 100644
--- a/lib/bsearch.c
+++ b/lib/bsearch.c
@@ -33,13 +33,13 @@
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)
- end = mid - 1;
+ end = mid;
else if (result > 0)
start = mid + 1;
else
--
1.6.5.2.153.g6e31f.dirty
next parent reply other threads:[~2009-11-11 15:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1257864802.git.andre.goddard@gmail.com>
2009-11-10 15:00 ` André Goddard Rosa [this message]
2009-11-10 15:00 ` [PATCH v4 2/2] bsearch: prevent overflow when computing middle comparison element André Goddard Rosa
2009-11-11 15:09 ` Thiago Farina
2009-11-11 15:28 ` Thiago Farina
2009-11-12 13:06 ` Rusty Russell
2009-11-12 13:23 ` André Goddard Rosa
2009-11-13 15:03 ` Thiago Farina
2009-11-13 23:42 ` Rusty Russell
[not found] ` <AANLkTinhg-ZgQRQ5KUXR-FeTa9zo+cUF+3vZykzeaHwE@mail.gmail.com>
2010-09-23 1:26 ` Rusty Russell
2010-09-24 5:50 ` matt mooney
2010-10-04 23:32 ` Rusty Russell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=28b3abe6d9a03d4251c0b42a3505c8bc5f861e69.1257864802.git.andre.goddard@gmail.com \
--to=andre.goddard@gmail.com \
--cc=alan-jenkins@tuffmail.co.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
--cc=tabbott@ksplice.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®