From 473a9dae23d46a4ec1827e4d68363eea805c08dc Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Wed, 31 Jan 2024 22:23:31 -0500 Subject: check for UB in qsort() and bsearch() --- src/stdlib/qsort.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/stdlib/qsort.c') diff --git a/src/stdlib/qsort.c b/src/stdlib/qsort.c index 346dba88..5d30cb3b 100644 --- a/src/stdlib/qsort.c +++ b/src/stdlib/qsort.c @@ -1,4 +1,5 @@ #include +#define NEED_COMPAR #include "_stdlib.h" /** sort an array **/ @@ -24,8 +25,7 @@ static void __qsort(char *base, size_t size, size_t lo, size_t hi, int (*compar) } for (j = lo; j < hi; j++) { - /* TODO: ensure compar() doesn't modify things */ - if (compar(base + (size * j), base + (size * hi)) < 0) { + if (SAFE_COMPAR(compar, base + (size * j), base + (size * hi), size, "qsort") < 0) { __swap(base, size, i, j); i++; } -- cgit v1.2.1