diff options
author | Jakob Kaivo <jkk@ung.org> | 2024-01-31 16:40:42 -0500 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2024-01-31 16:40:42 -0500 |
commit | d792c9d2797a5160e23827abdc71bfe500009cd3 (patch) | |
tree | e3bcc43c92e69869be755fe8cbaf623aa1981cbc /src/stdlib/bsearch.c | |
parent | 1a22e9f3c62fb248725874b64b8953392c004bca (diff) |
add UB checks for search/sort
Diffstat (limited to 'src/stdlib/bsearch.c')
-rw-r--r-- | src/stdlib/bsearch.c | 5 |
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)); |