]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/attr.c
fix previous commit (ITS#5819)
[openldap] / servers / slapd / attr.c
index 7112358c1e5b25f6aef363b8aaa9a2a768c0b449..4d578d9247de59f2db3e685a51f444716e2c36a7 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2007 The OpenLDAP Foundation.
+ * Copyright 1998-2008 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -211,8 +211,9 @@ attrs_free( Attribute *a )
 static void
 attr_dup2( Attribute *tmp, Attribute *a )
 {
+       tmp->a_flags = a->a_flags & SLAP_ATTR_PERSISTENT_FLAGS;
        if ( a->a_vals != NULL ) {
-               int     i;
+               unsigned        i, j;
 
                tmp->a_numvals = a->a_numvals;
                tmp->a_vals = ch_malloc( (tmp->a_numvals + 1) * sizeof(struct berval) );
@@ -227,7 +228,6 @@ attr_dup2( Attribute *tmp, Attribute *a )
                assert( a->a_nvals != NULL );
 
                if ( a->a_nvals != a->a_vals ) {
-                       int     j;
 
                        tmp->a_nvals = ch_malloc( (tmp->a_numvals + 1) * sizeof(struct berval) );
                        for ( j = 0; !BER_BVISNULL( &a->a_nvals[j] ); j++ ) {
@@ -290,11 +290,16 @@ attr_valfind(
        void *ctx )
 {
        struct berval nval = BER_BVNULL, *cval;
-       MatchingRule *mr = a->a_desc->ad_type->sat_equality;
+       MatchingRule *mr;
        const char *text;
        int match = -1, rc;
        unsigned i;
 
+       if ( flags & SLAP_MR_ORDERING )
+               mr = a->a_desc->ad_type->sat_ordering;
+       else
+               mr = a->a_desc->ad_type->sat_equality;
+
        if( !SLAP_IS_MR_ASSERTED_VALUE_NORMALIZED_MATCH( flags ) &&
                mr->smr_normalize )
        {
@@ -312,9 +317,8 @@ attr_valfind(
        }
 
        if ( a->a_flags & SLAP_ATTR_SORTED_VALS ) {
-       /* Binary search */
+               /* Binary search */
                unsigned base = 0, n = a->a_numvals;
-               int val = 0;
 
                while ( 0 < n ) {
                        unsigned pivot = n >> 1;
@@ -323,11 +327,14 @@ attr_valfind(
                                &a->a_nvals[i], cval, &text );
                        if ( rc == LDAP_SUCCESS && match == 0 )
                                break;
-                       n = pivot;
-                       if ( match > 0 )
+                       if ( match < 0 ) {
                                base = i+1;
+                               n -= pivot+1;
+                       } else {
+                               n = pivot;
+                       }
                }
-               if ( match > 0 )
+               if ( match < 0 )
                        i++;
        } else {
        /* Linear search */
@@ -340,7 +347,8 @@ attr_valfind(
                                break;
                }
        }
-       *slot = i;
+       if ( slot )
+               *slot = i;
        if ( match )
                rc = LDAP_NO_SUCH_ATTRIBUTE;
        if ( nval.bv_val )
@@ -395,14 +403,14 @@ attr_valadd(
                                        rc = LDAP_TYPE_OR_VALUE_EXISTS;
                                return rc;
                        }
-                       for ( j = a->a_numvals; j > slot; j-- ) {
+                       for ( j = a->a_numvals; j >= (int)slot; j-- ) {
                                a->a_vals[j+1] = a->a_vals[j];
                                if ( nvals )
                                        a->a_nvals[j+1] = a->a_nvals[j];
                        }
-                       ber_dupbv( &a->a_nvals[j], &v2[i] );
+                       ber_dupbv( &a->a_nvals[slot], &v2[i] );
                        if ( nvals )
-                               ber_dupbv( &a->a_vals[j], &vals[i] );
+                               ber_dupbv( &a->a_vals[slot], &vals[i] );
                        a->a_numvals++;
                }
                BER_BVZERO( &a->a_vals[a->a_numvals] );