ldb:"ldb_schema_attribute_by_name_internal" - support the whole unsigned int range
authorMatthias Dieter Wallnöfer <mdw@samba.org>
Tue, 19 Oct 2010 09:30:24 +0000 (11:30 +0200)
committerMatthias Dieter Wallnöfer <mdw@samba.org>
Tue, 19 Oct 2010 10:52:08 +0000 (10:52 +0000)
Commit 8556602b048e825b35df314d6865f997823ec2bb wasn't quite right - it only
restored the functionality on the positive integer range.

This one however should now really support the whole unsigned range.

Autobuild-User: Matthias Dieter Wallnöfer <mdw@samba.org>
Autobuild-Date: Tue Oct 19 10:52:08 UTC 2010 on sn-devel-104

source4/lib/ldb/common/ldb_attributes.c

index ea6fafd21ab78af6b9e8b9af21df9a06b664a422..21a3e6eb93b8f48a4fbd326a8357439f16c1a86d 100644 (file)
@@ -123,8 +123,8 @@ static const struct ldb_schema_attribute *ldb_schema_attribute_by_name_internal(
        const char *name)
 {
        /* for binary search we need signed variables */
-       int r, i, e, b = 0;
-       unsigned int u_i;
+       unsigned int i, e, b = 0;
+       int r;
        const struct ldb_schema_attribute *def = &ldb_attribute_default;
 
        /* as handlers are sorted, '*' must be the first if present */
@@ -136,20 +136,18 @@ static const struct ldb_schema_attribute *ldb_schema_attribute_by_name_internal(
        /* do a binary search on the array */
        e = ldb->schema.num_attributes - 1;
 
-       while (b <= e) {
+       while ((b <= e) && (e != (unsigned int) -1)) {
                i = (b + e) / 2;
 
-               u_i = (unsigned int) i;
-               r = ldb_attr_cmp(name, ldb->schema.attributes[u_i].name);
+               r = ldb_attr_cmp(name, ldb->schema.attributes[i].name);
                if (r == 0) {
-                       return &ldb->schema.attributes[u_i];
+                       return &ldb->schema.attributes[i];
                }
                if (r < 0) {
                        e = i - 1;
                } else {
                        b = i + 1;
                }
-
        }
 
        return def;