diff options
| author | Jakob Kaivo <jkk@ung.org> | 2024-01-31 22:23:31 -0500 |
|---|---|---|
| committer | Jakob Kaivo <jkk@ung.org> | 2024-01-31 22:23:31 -0500 |
| commit | 473a9dae23d46a4ec1827e4d68363eea805c08dc (patch) | |
| tree | 7e7bd01cc492be6b01f3a26c747a1a79b9ef95a0 /src/stdlib/qsort.c | |
| parent | 656d95bc6b5a2c55c79b07a70661137ea55cb0b4 (diff) | |
check for UB in qsort() and bsearch()
Diffstat (limited to 'src/stdlib/qsort.c')
| -rw-r--r-- | src/stdlib/qsort.c | 4 |
1 files changed, 2 insertions, 2 deletions
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 <stdlib.h> +#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++; } |
