]> git.sur5r.net Git - openldap/commitdiff
ldap_int_bisect_find(): Silence harmless "may be used uninitialized" warning
authorHallvard Furuseth <hallvard@openldap.org>
Thu, 10 Jan 2008 18:34:40 +0000 (18:34 +0000)
committerHallvard Furuseth <hallvard@openldap.org>
Thu, 10 Jan 2008 18:34:40 +0000 (18:34 +0000)
libraries/libldap/abandon.c

index a4fefb8953debf2ea3f5095651e71236fd26e48e..8f2fb3419499583f22babc83938cba956afc923e 100644 (file)
@@ -355,8 +355,7 @@ ldap_int_bisect_find( ber_int_t *v, ber_len_t n, ber_int_t id, int *idxp )
        begin = 0;
        end = n - 1;
 
-       if ( n > 0 ) {
-               if ( id < v[ begin ] ) {
+               if ( n <= 0 || id < v[ begin ] ) {
                        *idxp = 0;
 
                } else if ( id > v[ end ] ) {
@@ -366,7 +365,7 @@ ldap_int_bisect_find( ber_int_t *v, ber_len_t n, ber_int_t id, int *idxp )
                        int             pos;
                        ber_int_t       curid;
        
-                       while ( end >= begin ) {
+                       do {
                                pos = (begin + end)/2;
                                curid = v[ pos ];
        
@@ -374,25 +373,18 @@ ldap_int_bisect_find( ber_int_t *v, ber_len_t n, ber_int_t id, int *idxp )
                                        end = pos - 1;
        
                                } else if ( id > curid ) {
-                                       begin = pos + 1;
+                                       begin = ++pos;
        
                                } else {
                                        /* already abandoned? */
-                                       *idxp = pos;
                                        rc = 1;
                                        break;
                                }
-                       }
+                       } while ( end >= begin );
        
-                       if ( rc == 0 ) {
-                               *idxp = pos + ( id > curid ? 1 : 0 );
-                       }
+                       *idxp = pos;
                }
 
-       } else {
-               *idxp = 0;
-       }
-
        return rc;
 }