/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1998-2007 The OpenLDAP Foundation.
+ * Copyright 1998-2010 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
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 )
{
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 ] ) {
int pos;
ber_int_t curid;
- while ( end >= begin ) {
+ do {
pos = (begin + end)/2;
curid = v[ pos ];
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;
}
assert( vp != NULL );
assert( np != NULL );
- assert( *np >= 0 );
assert( idx >= 0 );
- assert( idx <= *np );
+ assert( (unsigned) idx <= *np );
n = *np;
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;