From 3e1f6b36c2968d0c3dd72bcf4675a5fd8497af62 Mon Sep 17 00:00:00 2001 From: Quanah Gibson-Mount <quanah@openldap.org> Date: Sun, 12 Dec 2010 05:14:55 +0000 Subject: [PATCH] ITS#6715 more fixes --- servers/slapd/attr.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/servers/slapd/attr.c b/servers/slapd/attr.c index b636996d60..4472d7c6ff 100644 --- a/servers/slapd/attr.c +++ b/servers/slapd/attr.c @@ -293,7 +293,7 @@ attr_valfind( MatchingRule *mr; const char *text; int match = -1, rc; - unsigned i; + unsigned i, n; if ( flags & SLAP_MR_ORDERING ) mr = a->a_desc->ad_type->sat_ordering; @@ -316,11 +316,12 @@ attr_valfind( cval = val; } - if ( a->a_flags & SLAP_ATTR_SORTED_VALS ) { + n = a->a_numvals; + if ( (a->a_flags & SLAP_ATTR_SORTED_VALS) && n ) { /* Binary search */ - unsigned base = 0, n = a->a_numvals; + unsigned base = 0; - while ( 0 < n ) { + do { unsigned pivot = n >> 1; i = base + pivot; rc = value_match( &match, a->a_desc, mr, flags, @@ -333,12 +334,12 @@ attr_valfind( } else { n = pivot; } - } + } while ( n ); if ( match < 0 ) i++; } else { /* Linear search */ - for ( i = 0; i < a->a_numvals; i++ ) { + for ( i = 0; i < n; i++ ) { const char *text; rc = ordered_value_match( &match, a->a_desc, mr, flags, @@ -347,10 +348,10 @@ attr_valfind( break; } } - if ( slot ) - *slot = i; if ( match ) rc = LDAP_NO_SUCH_ATTRIBUTE; + if ( slot ) + *slot = i; if ( nval.bv_val ) slap_sl_free( nval.bv_val, ctx ); -- GitLab