mirror of
https://github.com/isar/libmdbx.git
synced 2024-10-30 23:39:19 +08:00
mdbx: add paranoid assertions to qsort and bsearch macros.
Change-Id: I68efcf83576dd01e2f0c37ca8afb30967f5369a9
This commit is contained in:
parent
e3b5381f30
commit
aa92d6b7e7
@ -988,6 +988,8 @@ static int lcklist_detach_locked(MDBX_env *env) {
|
|||||||
\
|
\
|
||||||
SORT_SHELLPASS(TYPE, CMP, begin, end, 8); \
|
SORT_SHELLPASS(TYPE, CMP, begin, end, 8); \
|
||||||
SORT_SHELLPASS(TYPE, CMP, begin, end, 1); \
|
SORT_SHELLPASS(TYPE, CMP, begin, end, 1); \
|
||||||
|
for (TYPE *scan = begin + 1; scan < end; ++scan) \
|
||||||
|
assert(CMP(scan[-1], scan[0])); \
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
@ -996,6 +998,8 @@ static int lcklist_detach_locked(MDBX_env *env) {
|
|||||||
#define SEARCH_IMPL(NAME, TYPE_LIST, TYPE_ARG, CMP) \
|
#define SEARCH_IMPL(NAME, TYPE_LIST, TYPE_ARG, CMP) \
|
||||||
static __always_inline TYPE_LIST *NAME(TYPE_LIST *first, unsigned length, \
|
static __always_inline TYPE_LIST *NAME(TYPE_LIST *first, unsigned length, \
|
||||||
const TYPE_ARG item) { \
|
const TYPE_ARG item) { \
|
||||||
|
TYPE_LIST *const begin = first, *const end = begin + length; \
|
||||||
|
\
|
||||||
while (length > 3) { \
|
while (length > 3) { \
|
||||||
const unsigned half = length >> 1; \
|
const unsigned half = length >> 1; \
|
||||||
TYPE_LIST *const middle = first + half; \
|
TYPE_LIST *const middle = first + half; \
|
||||||
@ -1023,6 +1027,13 @@ static int lcklist_detach_locked(MDBX_env *env) {
|
|||||||
if (CMP(*first, item)) \
|
if (CMP(*first, item)) \
|
||||||
++first; \
|
++first; \
|
||||||
} \
|
} \
|
||||||
|
\
|
||||||
|
for (TYPE_LIST *scan = begin; scan < first; ++scan) \
|
||||||
|
assert(CMP(*scan, item)); \
|
||||||
|
for (TYPE_LIST *scan = first; scan < end; ++scan) \
|
||||||
|
assert(!CMP(*scan, item)); \
|
||||||
|
(void)begin, (void)end; \
|
||||||
|
\
|
||||||
return first; \
|
return first; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user