From: Rusty Russell <rusty@rustcorp.com.au>
To: "André Goddard Rosa" <andre.goddard@gmail.com>
Cc: tabbott@ksplice.com, alan-jenkins@tuffmail.co.uk,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/2] bsearch: prevent overflow when computing middle comparison element
Date: Wed, 11 Nov 2009 10:48:46 +1030 [thread overview]
Message-ID: <200911111048.46705.rusty@rustcorp.com.au> (raw)
In-Reply-To: <d748022cff75d9c09afc93b77cb16a683136cd13.1257778258.git.andre.goddard@gmail.com>
On Tue, 10 Nov 2009 02:12:31 am André Goddard Rosa wrote:
> It's really difficult to occur in practice because the sum of the lower
> and higher limits must overflow an int variable, but it can occur when
> working with large arrays. We'd better safe than sorry by avoiding this
> overflow situation when computing the middle element for comparison.
I always thought the obvious answer was:
mid = start + (end - start)/2;
Your version does nothing for 32 bit platforms...
Rusty.
next prev parent reply other threads:[~2009-11-11 0:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-09 14:53 [PATCH v2 0/2] bsearch: fix overflow and avoid unnecessary calculation André Goddard Rosa
2009-11-09 14:53 ` [PATCH v2 1/2] bsearch: avoid unneeded decrement arithmetic André Goddard Rosa
2009-11-09 14:53 ` [PATCH v2 2/2] bsearch: prevent overflow when computing middle comparison element André Goddard Rosa
2009-11-11 0:18 ` Rusty Russell [this message]
2009-11-11 15:00 ` [PATCH v3 " André Goddard Rosa
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=200911111048.46705.rusty@rustcorp.com.au \
--to=rusty@rustcorp.com.au \
--cc=alan-jenkins@tuffmail.co.uk \
--cc=andre.goddard@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--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