summaryrefslogtreecommitdiff
path: root/lib/ldb-samba
diff options
context:
space:
mode:
authorGarming Sam <garming@catalyst.net.nz>2019-04-05 10:22:28 +1300
committerAndrew Bartlett <abartlet@samba.org>2019-04-08 02:07:23 +0000
commitdb584d50817b6d0dc186c0b00de47e4c2b6681cf (patch)
tree577362c2dd9998cafa358000fe71390152666496 /lib/ldb-samba
parentc9b2a37268e793f2d8a8e3a6a340d2bc869f3f0e (diff)
downloadsamba-db584d50817b6d0dc186c0b00de47e4c2b6681cf.tar.gz
schema_syntax: Add comments for our index format functions
We had to devise our own scheme for writing integers in a human readable format which also sorted correctly numerically. This might look a bit confusing to outsiders, so here's a large comment as a peace offering. Pair-programmed-with: Tim Beale <timbeale@catalyst.net.nz> Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'lib/ldb-samba')
-rw-r--r--lib/ldb-samba/ldif_handlers.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/ldb-samba/ldif_handlers.c b/lib/ldb-samba/ldif_handlers.c
index bd8b63c42ed..23d0860dd9b 100644
--- a/lib/ldb-samba/ldif_handlers.c
+++ b/lib/ldb-samba/ldif_handlers.c
@@ -835,7 +835,22 @@ static int ldif_canonicalise_int32(struct ldb_context *ldb, void *mem_ctx,
return 0;
}
-/* Lexicographically sorted representation for a 32-bit integer */
+/*
+ * Lexicographically sorted representation for a 32-bit integer
+ *
+ * [ INT32_MIN ... -3, -2, -1 | 0 | +1, +2, +3 ... INT32_MAX ]
+ * n o p
+ *
+ * Refer to the comment in lib/ldb/common/attrib_handlers.c for the
+ * corresponding documentation for 64-bit integers.
+ *
+ * The same rules apply but use INT32_MIN and INT32_MAX.
+ *
+ * String representation padding is done to 10 characters.
+ *
+ * INT32_MAX = 2^31 - 1 = 2147483647 (10 characters long)
+ *
+ */
static int ldif_index_format_int32(struct ldb_context *ldb,
void *mem_ctx,
const struct ldb_val *in,
@@ -852,6 +867,10 @@ static int ldif_index_format_int32(struct ldb_context *ldb,
}
if (i < 0) {
+ /*
+ * i is negative, so this is subtraction rather than
+ * wrap-around.
+ */
prefix = 'n';
i = INT32_MAX + i + 1;
} else if (i > 0) {