]> pd.if.org Git - pdclib/blobdiff - functions/stdlib/bsearch.c
Comment cleanups.
[pdclib] / functions / stdlib / bsearch.c
index b9a33c65064fc64fd11470b4f58ed504e10da909..335b4f6acad60035a560234613b0e2faa5f32530 100644 (file)
@@ -1,7 +1,3 @@
-/* $Id$ */
-
-/* Release $Name$ */
-
 /* bsearch( const void *, const void *, size_t, size_t, int(*)( const void *, const void * ) )
 
    This file is part of the Public Domain C Library (PDCLib).
@@ -16,18 +12,19 @@ void * bsearch( const void * key, const void * base, size_t nmemb, size_t size,
 {
     const void * pivot;
     int rc;
-    int corr;
+    size_t corr;
     while ( nmemb )
     {
         /* algorithm needs -1 correction if remaining elements are an even number. */
-        corr = ( nmemb % 2 ) - 1;
+        corr = nmemb % 2;
         nmemb /= 2;
         pivot = (const char *)base + (nmemb * size);
         rc = compar( key, pivot );
         if ( rc > 0 )
         {
             base = (const char *)pivot + size;
-            nmemb += corr;
+            /* applying correction */
+            nmemb -= ( 1 - corr );
         }
         else if ( rc == 0 )
         {