From 83c4ad778e6ffcd3e672a068a8e62f1611531298 Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Thu, 22 Dec 2016 16:09:22 +1300 Subject: [PATCH] binsearch: make BINARY_ARRAY_SEARCH_GTE compare against a pointer This is in preparation for improvements in our handling of linked attributes where we make changes to the pointer in the process of comparing it (for caching purposes). Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- lib/util/binsearch.h | 2 +- lib/util/tests/binsearch.c | 9 +++++++-- source4/dsdb/samdb/ldb_modules/vlv_pagination.c | 6 +++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/util/binsearch.h b/lib/util/binsearch.h index 454e5ce4742..4204c9c6fca 100644 --- a/lib/util/binsearch.h +++ b/lib/util/binsearch.h @@ -103,7 +103,7 @@ if ((array_size) > 0) { \ for (_b = 0, _e = (array_size)-1; _b <= _e; ) { \ int32_t _i = (_b + _e) / 2; \ - int _r = comparison_fn(target, array[_i]); \ + int _r = comparison_fn(target, &array[_i]); \ if (_r == 0) { \ (exact) = &array[_i]; \ _e = _i - 1; \ diff --git a/lib/util/tests/binsearch.c b/lib/util/tests/binsearch.c index c6ef47e85d0..b3ecda165f3 100644 --- a/lib/util/tests/binsearch.c +++ b/lib/util/tests/binsearch.c @@ -31,6 +31,11 @@ static int int_cmp(int a, int b) return a - b; } +static int int_cmp_p(int a, int *b) +{ + return a - *b; +} + static bool test_binsearch_v(struct torture_context *tctx) { int array[] = { -11, -7, 0, 1, 723, 1000000}; @@ -72,7 +77,7 @@ static bool test_binsearch_gte(struct torture_context *tctx) i, target); BINARY_ARRAY_SEARCH_GTE(array, a_len, target, - int_cmp, result, next); + int_cmp_p, result, next); if (result == NULL) { /* we think there is no exact match */ @@ -134,7 +139,7 @@ static bool test_binsearch_gte(struct torture_context *tctx) i, target); BINARY_ARRAY_SEARCH_GTE(array, a_len, target, - int_cmp, result, result); + int_cmp_p, result, result); if (result == NULL) { /* we think the target is greater than all elements */ diff --git a/source4/dsdb/samdb/ldb_modules/vlv_pagination.c b/source4/dsdb/samdb/ldb_modules/vlv_pagination.c index bd8df7def53..5b744e3c181 100644 --- a/source4/dsdb/samdb/ldb_modules/vlv_pagination.c +++ b/source4/dsdb/samdb/ldb_modules/vlv_pagination.c @@ -232,7 +232,7 @@ static int send_referrals(struct results_store *store, /* vlv_value_compare() is used in a binary search */ static int vlv_value_compare(struct vlv_sort_context *target, - struct GUID guid) + struct GUID *guid) { struct ldb_result *result = NULL; struct ldb_message_element *el = NULL; @@ -243,7 +243,7 @@ static int vlv_value_compare(struct vlv_sort_context *target, NULL }; - ret = vlv_search_by_dn_guid(ac->module, ac, &result, &guid, attrs); + ret = vlv_search_by_dn_guid(ac->module, ac, &result, guid, attrs); if (ret != LDB_SUCCESS) { target->status = ret; @@ -259,7 +259,7 @@ static int vlv_value_compare(struct vlv_sort_context *target, /* The same as vlv_value_compare() but sorting in the opposite direction. */ static int vlv_value_compare_rev(struct vlv_sort_context *target, - struct GUID guid) + struct GUID *guid) { return -vlv_value_compare(target, guid); }