summaryrefslogtreecommitdiff
path: root/src/stdlib/bsearch.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2024-01-31 16:40:42 -0500
committerJakob Kaivo <jkk@ung.org>2024-01-31 16:40:42 -0500
commitd792c9d2797a5160e23827abdc71bfe500009cd3 (patch)
treee3bcc43c92e69869be755fe8cbaf623aa1981cbc /src/stdlib/bsearch.c
parent1a22e9f3c62fb248725874b64b8953392c004bca (diff)
add UB checks for search/sort
Diffstat (limited to 'src/stdlib/bsearch.c')
-rw-r--r--src/stdlib/bsearch.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/stdlib/bsearch.c b/src/stdlib/bsearch.c
index ae60783e..c710406e 100644
--- a/src/stdlib/bsearch.c
+++ b/src/stdlib/bsearch.c
@@ -12,9 +12,14 @@ void * bsearch(const void * key, const void * base, size_t nmemb, size_t size, i
const char *addr = base;
SIGNAL_SAFE(0);
+ ASSERT_NONNULL(key);
+ ASSERT_NONNULL(base);
/* overlap can't be detected because the size of key can't be known */
+ /* TODO: ensure everything is in order to start with */
+
while (ret == NULL) {
+ /* TODO: ensure compar doesn't modify things */
int comp = compar(key, addr + (i * size));
if (comp == 0) {
return (void*)(addr + (i * size));