]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/abandon.c
ITS#6262
[openldap] / libraries / libldap / abandon.c
index 568c073868aeaf1d441f4382c8238aaabfdfabc4..d8cb33128dd6631d808b85d83cbd042dc42dba72 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2006 The OpenLDAP Foundation.
+ * Copyright 1998-2010 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -224,8 +224,9 @@ start_again:;
                        i = ++(ld)->ld_msgid;
 #ifdef LDAP_CONNECTIONLESS
                        if ( LDAP_IS_UDP(ld) ) {
-                               err = ber_write( ber, ld->ld_options.ldo_peer,
-                                       sizeof(struct sockaddr), 0);
+                               struct sockaddr sa = {0};
+                               /* dummy, filled with ldo_peer in request.c */
+                               err = ber_write( ber, &sa, sizeof(sa), 0 );
                        }
                        if ( LDAP_IS_UDP(ld) && ld->ld_options.ldo_version ==
                                LDAP_VERSION2 )
@@ -346,17 +347,14 @@ ldap_int_bisect_find( ber_int_t *v, ber_len_t n, ber_int_t id, int *idxp )
 {
        int             begin,
                        end,
-                       i,
                        rc = 0;
 
-       assert( n >= 0 );
        assert( id >= 0 );
 
        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 +364,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 +372,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;
 }
 
@@ -418,9 +409,8 @@ ldap_int_bisect_insert( ber_int_t **vp, ber_len_t *np, int id, int idx )
 
        assert( vp != NULL );
        assert( np != NULL );
-       assert( *np >= 0 );
        assert( idx >= 0 );
-       assert( idx <= *np );
+       assert( (unsigned) idx <= *np );
 
        n = *np;
 
@@ -455,14 +445,12 @@ int
 ldap_int_bisect_delete( ber_int_t **vp, ber_len_t *np, int id, int idx )
 {
        ber_int_t       *v;
-       ber_len_t       n;
-       int             i;
+       ber_len_t       i, n;
 
        assert( vp != NULL );
        assert( np != NULL );
-       assert( *np >= 0 );
        assert( idx >= 0 );
-       assert( idx < *np );
+       assert( (unsigned) idx < *np );
 
        v = *vp;