summaryrefslogtreecommitdiff
path: root/src/shared/util.h
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-10-11 19:33:13 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-10-13 17:56:54 -0400
commit7ff7394d9e4e9189c30fd018235e6b1728c6f2d0 (patch)
tree37a98cdb42d8b62b56aeb6fad7fd00299449d38d /src/shared/util.h
parentfb1316462952d17d6ebf19c3f093b730c13016a7 (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.
Diffstat (limited to 'src/shared/util.h')
-rw-r--r--src/shared/util.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/shared/util.h b/src/shared/util.h
index 26af5b30af..09e556d011 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -772,3 +772,15 @@ bool id128_is_valid(const char *s) _pure_;
void parse_user_at_host(char *arg, char **user, char **host);
int split_pair(const char *s, const char *sep, char **l, char **r);
+
+/**
+ * Normal qsort requires base to be nonnull. Here were require
+ * that only if nmemb > 0.
+ */
+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);
+ }
+}