Ensured calls to bsearch() have a length of at least 1; UndefinedBehaviorSanitizer will warn otherwise. Also included qsort(), to be safe.

This commit is contained in:
Pietro Gagliardi 2019-06-02 14:26:25 -04:00
parent 6d6cd66046
commit 12c01d0d42
1 changed files with 4 additions and 1 deletions

View File

@ -77,12 +77,15 @@ void sharedbitsPrefixName(ArrayDeleteItem)(sharedbitsPrefixName(Array) *arr, voi
void *sharedbitsPrefixName(ArrayBsearch)(const sharedbitsPrefixName(Array) *arr, const void *key, int (*compare)(const void *, const void *))
{
if (arr->len == 0)
return NULL;
return bsearch(key, arr->buf, arr->len, arr->elemsize, compare);
}
void sharedbitsPrefixName(ArrayQsort)(sharedbitsPrefixName(Array) *arr, int (*compare)(const void *, const void *))
{
qsort(arr->buf, arr->len, arr->elemsize, compare);
if (arr->len != 0)
qsort(arr->buf, arr->len, arr->elemsize, compare);
}
#include "end.h"