Messages in this thread | | | From | Rusty Russell <> | Subject | Re: [PATCH v3 2/2] bsearch: prevent overflow when computing middle comparison element | Date | Wed, 11 Nov 2009 10:48:46 +1030 |
| |
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. -- 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/
| |