summaryrefslogtreecommitdiff
path: root/src/libudev/util.h
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-01-09 14:44:53 -0500
committerAnthony G. Basile <blueness@gentoo.org>2014-01-09 14:44:53 -0500
commitcc10c90a378db31a880b510c0d6c21a091769dd2 (patch)
tree4fa8d8d51e5d1331a1c9e5cd6fee94540ec4105f /src/libudev/util.h
parent855ce449eba82c417c005d17aa680aba2048ed8d (diff)
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 <blueness@gentoo.org>
Diffstat (limited to 'src/libudev/util.h')
-rw-r--r--src/libudev/util.h8
1 files changed, 8 insertions, 0 deletions
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);
+ }
+}