delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/03/26/19:55:06

From: khan AT xraylith DOT wisc DOT edu (Mumit Khan)
Subject: Re: nasty bug in bsearch() in b17.1 under Windows'95????
26 Mar 1997 19:55:06 -0800 :
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <9703260454.AA00258.cygnus.gnu-win32@modi.xraylith.wisc.edu>
Original-To: Jim Balter <jqb AT netcom DOT com>
Original-Cc: gnu-win32 AT cygnus DOT com
In-Reply-To: Your message of "Tue, 25 Mar 1997 03:53:34 PST."
<3337BCBE DOT 1448 AT netcom DOT com>
Original-Sender: owner-gnu-win32 AT cygnus DOT com

Jim Balter <jqb AT netcom DOT com> writes:
> 
> The bsearch.c in newlib contains a quite explicit and quite erroneous
> comparison to the item one past the last range whenever the key isn't
> found.  Normally this is merely pointless extra work, but if the key is
> greater than the last element, then it is an out of bounds reference,
> just as you have discovered.  The "easiest" fix is to simply remove the
> lines
> 
>   if (compar (key, base) == 0)
>     return (_PTR) base;
> 

Exactly. Just looked at the source, and it's quite obvious. As you
mention, it also does an extra comparison for no reason whatsoever
in the other cases.

Here's the trivial patch, which took non-trivial number of hours
to find ;-) debugging f771 on a '95 box is no fun. 

*** bsearch.c.~1	Tue Mar 25 22:47:42 1997
--- bsearch.c	Tue Mar 25 22:47:46 1997
*************** _DEFUN (bsearch, (key, base, nmemb, size
*** 94,100 ****
      }
  
-   if (compar (key, base) == 0)
-     return (_PTR) base;
- 
    return NULL;
  }
--- 94,97 ----

Regards,
Mumit -- khan AT xraylith DOT wisc DOT edu
http://www.xraylith.wisc.edu/~khan/
-
For help on using this list, send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019