diff options
author | Andrew Tridgell <tridge@samba.org> | 2005-01-02 09:46:59 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:07:56 -0500 |
commit | 09a76e204cf339862f8b0b45979d65cc34aa3c36 (patch) | |
tree | 4d533b65f33d04d5b76d3435ad41b54c2998df44 /source4/lib/ldb/ldb_tdb | |
parent | 62ffbdb9f1d9ded63f6d8623f14741145a2d6b47 (diff) | |
download | samba-09a76e204cf339862f8b0b45979d65cc34aa3c36.tar.gz samba-09a76e204cf339862f8b0b45979d65cc34aa3c36.tar.bz2 samba-09a76e204cf339862f8b0b45979d65cc34aa3c36.zip |
r4477: expanded the test suite to increase code coverage a lot
(This used to be commit 4edbd1b18ee38e584cf844b64c7fcb2645921837)
Diffstat (limited to 'source4/lib/ldb/ldb_tdb')
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_index.c | 51 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_pack.c | 13 |
2 files changed, 52 insertions, 12 deletions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c index ff0cabb0d6..88ef997a03 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_index.c +++ b/source4/lib/ldb/ldb_tdb/ldb_index.c @@ -38,6 +38,57 @@ #include "ldb/ldb_tdb/ldb_tdb.h" #include "ldb/include/ldb_parse.h" +/* + find an element in a list, using the given comparison function and + assuming that the list is already sorted using comp_fn + + return -1 if not found, or the index of the first occurance of needle if found +*/ +static int ldb_list_find(const void *needle, + const void *base, size_t nmemb, size_t size, + comparison_fn_t comp_fn) +{ + const char *base_p = base; + size_t min_i, max_i, test_i; + + if (nmemb == 0) { + return -1; + } + + min_i = 0; + max_i = nmemb-1; + + while (min_i < max_i) { + int r; + + test_i = (min_i + max_i) / 2; + r = comp_fn(needle, *(void * const *)(base_p + (size * test_i))); + if (r == 0) { + /* scan back for first element */ + while (test_i > 0 && + comp_fn(needle, *(void * const *)(base_p + (size * (test_i-1)))) == 0) { + test_i--; + } + return test_i; + } + if (r < 0) { + if (test_i == 0) { + return -1; + } + max_i = test_i - 1; + } + if (r > 0) { + min_i = test_i + 1; + } + } + + if (comp_fn(needle, *(void * const *)(base_p + (size * min_i))) == 0) { + return min_i; + } + + return -1; +} + struct dn_list { unsigned int count; char **dn; diff --git a/source4/lib/ldb/ldb_tdb/ldb_pack.c b/source4/lib/ldb/ldb_tdb/ldb_pack.c index a548a4189b..4c1241d0bd 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_pack.c +++ b/source4/lib/ldb/ldb_tdb/ldb_pack.c @@ -139,16 +139,6 @@ int ltdb_pack_data(struct ldb_module *module, } /* - free the memory allocated from a ltdb_unpack_data() -*/ -void ltdb_unpack_data_free(struct ldb_module *module, - struct ldb_message *message) -{ - talloc_free(message->elements); -} - - -/* unpack a ldb message from a linear buffer in TDB_DATA Free with ltdb_unpack_data_free() @@ -267,7 +257,6 @@ int ltdb_unpack_data(struct ldb_module *module, return 0; failed: - ltdb_unpack_data_free(module, message); - + talloc_free(message->elements); return -1; } |