lkml.org 
[lkml]   [2009]   [Nov]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH v4 2/2] bsearch: prevent overflow when computing middle comparison element
From
On Wed, Nov 11, 2009 at 1:09 PM, Thiago Farina <tfransosi@gmail.com> wrote:
> 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.
>
I mean: size_t start = 0, end = num, mid;
--
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-11 16:31    [from the cache]
©2003-2011 Jasper Spaans