diff options
Diffstat (limited to 'src/basic/util.h')
-rw-r--r-- | src/basic/util.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/basic/util.h b/src/basic/util.h index c24fd6c63..6ffc54f98 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -100,6 +100,19 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size, #endif // 0 /** + * Normal bsearch requires base to be nonnull. Here were require + * that only if nmemb > 0. + */ +static inline void* bsearch_safe(const void *key, const void *base, + size_t nmemb, size_t size, comparison_fn_t compar) { + if (nmemb <= 0) + return NULL; + + assert(base); + return bsearch(key, base, nmemb, size, compar); +} + +/** * Normal qsort requires base to be nonnull. Here were require * that only if nmemb > 0. */ |