From d513108ea3a889a2585ec6c2e16c3a00ec028d2c Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sat, 1 Dec 2007 11:00:40 +0000 Subject: [PATCH] Fix sign bit --- servers/slapd/schema_init.c | 90 ++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index 3d9cbb3b61..cb18fbae5c 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -2112,6 +2112,46 @@ integerMatch( return LDAP_SUCCESS; } +static int +integerVal2Key( + struct berval *val, + struct berval *key, + struct berval *tmp +) +{ + int neg; + + if ( lutil_str2bin( val, tmp )) { + return LDAP_INVALID_SYNTAX; + } + + neg = tmp->bv_val[0] & 0x80; + + /* If too small, sign-extend */ + if ( tmp->bv_len < index_intlen ) { + int j, k, pad; + key->bv_val[0] = index_intlen; + k = index_intlen - tmp->bv_len + 1; + if ( neg ) + pad = 0xff; + else + pad = 0; + for ( j=1; jbv_val[j] = pad; + for ( j = 0; jbv_len; j++ ) + key->bv_val[j+k] = tmp->bv_val[j]; + } else { + key->bv_val[0] = tmp->bv_len; + memcpy( key->bv_val+1, tmp->bv_val, index_intlen ); + } + if ( neg ) { + key->bv_val[0] = -key->bv_val[0]; + } + /* convert signed to unsigned */ + key->bv_val[0] ^= 0x80; + return 0; +} + /* Index generation function */ static int integerIndexer( @@ -2157,32 +2197,11 @@ integerIndexer( } } iv = itmp; - if ( lutil_str2bin( &values[i], &iv )) { - rc = LDAP_INVALID_SYNTAX; + rc = integerVal2Key( &values[i], &keys[i], &iv ); + if ( rc ) goto leave; - } - /* If too small, sign-extend */ - if ( iv.bv_len < index_intlen ) { - int j, k, pad; - keys[i].bv_val[0] = index_intlen; - if (iv.bv_val[0] & 0x80) - pad = 0xff; - else - pad = 0; - k = index_intlen - iv.bv_len + 1; - for ( j=1; j