ldb:attrib_handlers: reduce non-transitive behaviour in ldb_comparison_fold
[pfilipensky/samba-autobuild/.git] / lib / ldb / common / attrib_handlers.c
index 1e3c550e40403564f2d0806e617872f14cd0d1d4..2344dc0c8afc8f890e126bafcd8b977b61229c40 100644 (file)
@@ -394,17 +394,27 @@ utf8str:
        b2 = ldb_casefold(ldb, mem_ctx, s2, n2);
 
        if (!b1 || !b2) {
-               /* One of the strings was not UTF8, so we have no
-                * options but to do a binary compare */
+               /*
+                * One of the strings was not UTF8, so we have no
+                * options but to do a binary compare.
+                */
                talloc_free(b1);
                talloc_free(b2);
                ret = memcmp(s1, s2, MIN(n1, n2));
                if (ret == 0) {
-                       if (n1 == n2) return 0;
+                       if (n1 == n2) {
+                               return 0;
+                       }
                        if (n1 > n2) {
-                               return (int)ldb_ascii_toupper(s1[n2]);
+                               if (s1[n2] == '\0') {
+                                       return 0;
+                               }
+                               return 1;
                        } else {
-                               return -(int)ldb_ascii_toupper(s2[n1]);
+                               if (s2[n1] == '\0') {
+                                       return 0;
+                               }
+                               return -1;
                        }
                }
                return ret;