From cc10c90a378db31a880b510c0d6c21a091769dd2 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Thu, 9 Jan 2014 14:44:53 -0500 Subject: Never call qsort on potentially NULL arrays This extends 62678ded 'efi: never call qsort on potentially NULL arrays' to all other places where qsort is used and it is not obvious that the count is non-zero. Signed-off-by: Anthony G. Basile --- src/libudev/util.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/libudev/util.h') diff --git a/src/libudev/util.h b/src/libudev/util.h index 18109938e0..88bd771a82 100644 --- a/src/libudev/util.h +++ b/src/libudev/util.h @@ -283,3 +283,11 @@ static inline void _reset_errno_(int *saved_errno) { } #define PROTECT_ERRNO _cleanup_(_reset_errno_) __attribute__((unused)) int _saved_errno_ = errno + +static inline void qsort_safe(void *base, size_t nmemb, size_t size, + int (*compar)(const void *, const void *)) { + if (nmemb) { + assert(base); + qsort(base, nmemb, size, compar); + } +} -- cgit v1.2.3-54-g00ecf