]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/attr.c
silence warning
[openldap] / servers / slapd / attr.c
index 4fcb7dc42f5a5452f5087ed2993cd4c6bfcf1686..51f50758fcef64af13444d83e73127ebdaacf357 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2010 The OpenLDAP Foundation.
+ * Copyright 1998-2011 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -88,6 +88,8 @@ attr_alloc( AttributeDescription *ad )
        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;
 }
@@ -317,11 +319,11 @@ attr_valfind(
        }
 
        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,
@@ -334,7 +336,7 @@ attr_valfind(
                        } else {
                                n = pivot;
                        }
-               }
+               } while ( n );
                if ( match < 0 )
                        i++;
        } else {