}
}
-Attribute *attr_dup( Attribute *a )
+Attribute *
+attr_dup( Attribute *a )
{
Attribute *tmp;
- if( a == NULL) return NULL;
+ if ( a == NULL) return NULL;
tmp = ch_malloc( sizeof(Attribute) );
- if( a->a_vals != NULL ) {
+ if ( a->a_vals != NULL ) {
int i;
- for( i=0; a->a_vals[i].bv_val != NULL; i++ ) {
+ for ( i = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ ) {
/* EMPTY */ ;
}
- tmp->a_vals = ch_malloc((i+1) * sizeof(struct berval));
- for( i=0; a->a_vals[i].bv_val != NULL; i++ ) {
+ tmp->a_vals = ch_malloc( (i + 1) * sizeof(struct berval) );
+ for ( i = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ ) {
ber_dupbv( &tmp->a_vals[i], &a->a_vals[i] );
- if( BER_BVISNULL( &tmp->a_vals[i] ) ) break;
+ if ( BER_BVISNULL( &tmp->a_vals[i] ) ) break;
+ /* FIXME: error? */
}
BER_BVZERO( &tmp->a_vals[i] );
- if( a->a_nvals != a->a_vals ) {
- tmp->a_nvals = ch_malloc((i+1) * sizeof(struct berval));
- for( i=0; a->a_nvals[i].bv_val != NULL; i++ ) {
+ /* a_nvals must be non null; it may be equal to a_vals */
+ assert( a->a_nvals );
+
+ if ( a->a_nvals != a->a_vals ) {
+ tmp->a_nvals = ch_malloc( (i + 1) * sizeof(struct berval) );
+ for ( i = 0; !BER_BVISNULL( &a->a_nvals[i] ); i++ ) {
ber_dupbv( &tmp->a_nvals[i], &a->a_nvals[i] );
- if( BER_BVISNULL( &tmp->a_nvals[i] ) ) break;
+ if ( BER_BVISNULL( &tmp->a_nvals[i] ) ) break;
+ /* FIXME: error? */
}
BER_BVZERO( &tmp->a_nvals[i] );
return tmp;
}
-Attribute *attrs_dup( Attribute *a )
+Attribute *
+attrs_dup( Attribute *a )
{
Attribute *tmp, **next;
rc = value_add( &(*a)->a_vals, vals );
- if( !rc && nvals ) rc = value_add( &(*a)->a_nvals, nvals );
- else (*a)->a_nvals = (*a)->a_vals;
+ if ( rc == LDAP_SUCCESS ) {
+ if ( nvals ) {
+ rc = value_add( &(*a)->a_nvals, nvals );
+ /* FIXME: what if rc != LDAP_SUCCESS ? */
+ } else {
+ (*a)->a_nvals = (*a)->a_vals;
+ }
+ }
return rc;
}
{
int i;
- for ( i = 0; vals[i].bv_val; i++ );
+ for ( i = 0; !BER_BVISNULL( &vals[i] ); i++ );
nvals = slap_sl_calloc( sizeof(struct berval), i + 1, memctx );
- for ( i = 0; vals[i].bv_val; i++ ) {
+ for ( i = 0; !BER_BVISNULL( &vals[i] ); i++ ) {
rc = (*desc->ad_type->sat_equality->smr_normalize)(
SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
desc->ad_type->sat_syntax,
&vals[i], &nvals[i], memctx );
if ( rc != LDAP_SUCCESS ) {
- BER_BVZERO( &nvals[i+1] );
+ BER_BVZERO( &nvals[i + 1] );
goto error_return;
}
}
rc = value_add_one( &(*a)->a_vals, val );
- if( !rc && nval ) rc = value_add_one( &(*a)->a_nvals, nval );
- else (*a)->a_nvals = (*a)->a_vals;
+ if ( rc == LDAP_SUCCESS ) {
+ if ( nval ) {
+ rc = value_add_one( &(*a)->a_nvals, nval );
+ /* FIXME: what if rc != LDAP_SUCCESS ? */
+ } else {
+ (*a)->a_nvals = (*a)->a_vals;
+ }
+ }
return rc;
}
void *memctx )
{
struct berval nval;
- struct berval *nvalp;
+ struct berval *nvalp = NULL;
int rc;
if ( desc->ad_type->sat_equality &&
return rc;
}
nvalp = &nval;
- } else {
- nvalp = NULL;
}
rc = attr_merge_one( e, desc, val, nvalp );
ber_dupbv( &e->e_nname, &frontendDB->be_schemandn );
e->e_private = NULL;
- vals[0].bv_val = "subentry";
- vals[0].bv_len = sizeof("subentry")-1;
- if( attr_merge_one( e, ad_structuralObjectClass, vals, vals ) ) {
+ BER_BVSTR( &vals[0], "subentry" );
+ if( attr_merge_one( e, ad_structuralObjectClass, vals, NULL ) ) {
/* Out of memory, do something about it */
entry_free( e );
*text = "out of memory";
return LDAP_OTHER;
}
- vals[0].bv_val = "top";
- vals[0].bv_len = sizeof("top")-1;
- vals[1].bv_val = "subentry";
- vals[1].bv_len = sizeof("subentry")-1;
- vals[2].bv_val = "subschema";
- vals[2].bv_len = sizeof("subschema")-1;
- vals[3].bv_val = "extensibleObject";
- vals[3].bv_len = sizeof("extensibleObject")-1;
- vals[4].bv_val = NULL;
- if( attr_merge( e, ad_objectClass, vals, vals ) ) {
+ BER_BVSTR( &vals[0], "top" );
+ BER_BVSTR( &vals[1], "subentry" );
+ BER_BVSTR( &vals[2], "subschema" );
+ BER_BVSTR( &vals[3], "extensibleObject" );
+ BER_BVZERO( &vals[4] );
+ if ( attr_merge( e, ad_objectClass, vals, NULL ) ) {
/* Out of memory, do something about it */
entry_free( e );
*text = "out of memory";
nvals[0].bv_len = frontendDB->be_schemandn.bv_len -
(nvals[0].bv_val - frontendDB->be_schemandn.bv_val);
- if( attr_merge_one( e, desc, vals, nvals ) ) {
+ if ( attr_merge_one( e, desc, vals, nvals ) ) {
/* Out of memory, do something about it */
entry_free( e );
*text = "out of memory";
vals[0].bv_val = timebuf;
vals[0].bv_len = strlen( timebuf );
- if( attr_merge_one( e, ad_createTimestamp, vals, vals ) ) {
+ if( attr_merge_one( e, ad_createTimestamp, vals, NULL ) ) {
/* Out of memory, do something about it */
entry_free( e );
*text = "out of memory";
return LDAP_OTHER;
}
- if( attr_merge_one( e, ad_modifyTimestamp, vals, vals ) ) {
+ if( attr_merge_one( e, ad_modifyTimestamp, vals, NULL ) ) {
/* Out of memory, do something about it */
entry_free( e );
*text = "out of memory";
int
value_add(
- BerVarray *vals,
- BerVarray addvals )
+ BerVarray *vals,
+ BerVarray addvals )
{
- int n, nn;
- BerVarray v2;
+ int n, nn = 0;
+ BerVarray v2;
- for ( nn = 0; addvals != NULL && addvals[nn].bv_val != NULL; nn++ )
- ; /* NULL */
+ if ( addvals != NULL ) {
+ for ( ; !BER_BVISNULL( &addvals[nn] ); nn++ )
+ ; /* NULL */
+ }
if ( *vals == NULL ) {
*vals = (BerVarray) SLAP_MALLOC( (nn + 1)
return LBER_ERROR_MEMORY;
}
n = 0;
+
} else {
- for ( n = 0; (*vals)[n].bv_val != NULL; n++ ) {
+ for ( n = 0; !BER_BVISNULL( &(*vals)[n] ); n++ ) {
; /* Empty */
}
*vals = (BerVarray) SLAP_REALLOC( (char *) *vals,
}
}
- v2 = *vals + n;
- for ( ; addvals->bv_val; v2++, addvals++ ) {
- ber_dupbv(v2, addvals);
- if (v2->bv_val == NULL) break;
+ v2 = &(*vals)[n];
+ for ( ; !BER_BVISNULL( addvals ); v2++, addvals++ ) {
+ ber_dupbv( v2, addvals );
+ if ( BER_BVISNULL( v2 ) ) break;
}
- v2->bv_val = NULL;
- v2->bv_len = 0;
+ BER_BVZERO( v2 );
return LDAP_SUCCESS;
}
int
value_add_one(
- BerVarray *vals,
- struct berval *addval )
+ BerVarray *vals,
+ struct berval *addval )
{
- int n;
- BerVarray v2;
+ int n;
+ BerVarray v2;
if ( *vals == NULL ) {
*vals = (BerVarray) SLAP_MALLOC( 2 * sizeof(struct berval) );
return LBER_ERROR_MEMORY;
}
n = 0;
+
} else {
- for ( n = 0; (*vals)[n].bv_val != NULL; n++ ) {
+ for ( n = 0; !BER_BVISNULL( &(*vals)[n] ); n++ ) {
; /* Empty */
}
*vals = (BerVarray) SLAP_REALLOC( (char *) *vals,
}
}
- v2 = *vals + n;
+ v2 = &(*vals)[n];
ber_dupbv(v2, addval);
v2++;
- v2->bv_val = NULL;
- v2->bv_len = 0;
+ BER_BVZERO( v2 );
return LDAP_SUCCESS;
}