ldb:ldb_tdb backend/indexes - DN comparison
authorMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>
Wed, 18 Nov 2009 09:44:56 +0000 (10:44 +0100)
committerAndrew Tridgell <tridge@samba.org>
Fri, 20 Nov 2009 01:26:37 +0000 (12:26 +1100)
- DN comparison: The function doesn't seem that efficient. I "upgraded" it a bit
  to be more powerful (added a second length check and do both before the string
  comparison)

source4/lib/ldb/ldb_tdb/ldb_index.c

index 55c5c9c9528134997aba0ec8c2afe90bac44f186..454dffbb614b6f76806d8e4fd8f2af90724a6f6d 100644 (file)
@@ -60,12 +60,13 @@ int ltdb_index_transaction_start(struct ldb_module *module)
  * differences in string termination */
 static int dn_list_cmp(const struct ldb_val *v1, const struct ldb_val *v2)
 {
-       int ret = strncmp((char *)v1->data, (char *)v2->data, v1->length);
-       if (ret != 0) return ret;
-       if (v2->length > v1->length && v2->data[v1->length] != 0) {
+       if (v1->length > v2->length && v1->data[v2->length] != 0) {
+               return -1;
+       }
+       if (v1->length < v2->length && v2->data[v1->length] != 0) {
                return 1;
        }
-       return 0;
+       return strncmp((char *)v1->data, (char *)v2->data, v1->length);
 }