mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thiago Farina <tfransosi@gmail.com>
To: "André Goddard Rosa" <andre.goddard@gmail.com>
Cc: tabbott@ksplice.com, alan-jenkins@tuffmail.co.uk,
	rusty@rustcorp.com.au, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 2/2] bsearch: prevent overflow when computing middle  comparison element
Date: Wed, 11 Nov 2009 13:09:57 -0200	[thread overview]
Message-ID: <a4c8a6d00911110709j65b54875sb9e56edf0a32c28d@mail.gmail.com> (raw)
In-Reply-To: <2bd27b061789ed14dd80816fd987273ae33ffbd1.1257864802.git.andre.goddard@gmail.com>

On Tue, Nov 10, 2009 at 1:00 PM, André Goddard Rosa
<andre.goddard@gmail.com> wrote:
>  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, mid, result;
> +       size_t start = 0, end = num;
> +       int result;
>
>        while (start < end) {
> -               mid = (start + end) / 2;
> +               size_t mid = start + (end - start) / 2;
I think it is more readable if you could keep the mid variable outside
of the while loop.

  reply	other threads:[~2009-11-11 15:09 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 ` [PATCH v4 1/2] bsearch: avoid unneeded decrement arithmetic André Goddard Rosa
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 [this message]
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=a4c8a6d00911110709j65b54875sb9e56edf0a32c28d@mail.gmail.com \
    --to=tfransosi@gmail.com \
    --cc=alan-jenkins@tuffmail.co.uk \
    --cc=andre.goddard@gmail.com \
    --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®