/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1998-2010 The OpenLDAP Foundation.
+ * Copyright 1998-2013 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
ldap_pvt_thread_mutex_unlock( &attr_mutex );
a->a_desc = ad;
+ if ( ad && ( ad->ad_type->sat_flags & SLAP_AT_SORTED_VAL ))
+ a->a_flags |= SLAP_ATTR_SORTED_VALS;
return a;
}
if ( a->a_nvals != a->a_vals ) {
tmp->a_nvals = ch_malloc( (tmp->a_numvals + 1) * sizeof(struct berval) );
- for ( j = 0; !BER_BVISNULL( &a->a_nvals[j] ); j++ ) {
- assert( j < i );
- ber_dupbv( &tmp->a_nvals[j], &a->a_nvals[j] );
- if ( BER_BVISNULL( &tmp->a_nvals[j] ) ) break;
- /* FIXME: error? */
+ j = 0;
+ if ( i ) {
+ for ( ; !BER_BVISNULL( &a->a_nvals[j] ); j++ ) {
+ assert( j < i );
+ ber_dupbv( &tmp->a_nvals[j], &a->a_nvals[j] );
+ if ( BER_BVISNULL( &tmp->a_nvals[j] ) ) break;
+ /* FIXME: error? */
+ }
+ assert( j == i );
}
- assert( j == i );
BER_BVZERO( &tmp->a_nvals[j] );
} else {
}
n = a->a_numvals;
- if ( a->a_flags & SLAP_ATTR_SORTED_VALS ) {
+ if ( (a->a_flags & SLAP_ATTR_SORTED_VALS) && n ) {
/* Binary search */
unsigned base = 0;
- while ( 0 < n ) {
+ do {
unsigned pivot = n >> 1;
i = base + pivot;
rc = value_match( &match, a->a_desc, mr, flags,
} else {
n = pivot;
}
- }
+ } while ( n );
if ( match < 0 )
i++;
} else {