summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libudev/conf-files.c2
-rw-r--r--src/libudev/libudev-enumerate.c2
-rw-r--r--src/libudev/util.h8
3 files changed, 10 insertions, 2 deletions
diff --git a/src/libudev/conf-files.c b/src/libudev/conf-files.c
index 2baefffad5..2d413999f9 100644
--- a/src/libudev/conf-files.c
+++ b/src/libudev/conf-files.c
@@ -127,7 +127,7 @@ static int conf_files_list_strv_internal(char ***strv, const char *suffix, const
return -ENOMEM;
}
- qsort(files, hashmap_size(fh), sizeof(char *), base_cmp);
+ qsort_safe(files, hashmap_size(fh), sizeof(char *), base_cmp);
*strv = files;
hashmap_free(fh);
diff --git a/src/libudev/libudev-enumerate.c b/src/libudev/libudev-enumerate.c
index 8146f27e4f..e71d766c02 100644
--- a/src/libudev/libudev-enumerate.c
+++ b/src/libudev/libudev-enumerate.c
@@ -276,7 +276,7 @@ _public_ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enume
size_t move_later_prefix = 0;
udev_list_cleanup(&udev_enumerate->devices_list);
- qsort(udev_enumerate->devices, udev_enumerate->devices_cur, sizeof(struct syspath), syspath_cmp);
+ qsort_safe(udev_enumerate->devices, udev_enumerate->devices_cur, sizeof(struct syspath), syspath_cmp);
max = udev_enumerate->devices_cur;
for (i = 0; i < max; i++) {
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);
+ }
+}