summaryrefslogtreecommitdiff
path: root/src/journal
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/journal
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/journal')
-rw-r--r--src/journal/catalog.c2
-rw-r--r--src/journal/journal-file.c2
-rw-r--r--src/journal/journal-vacuum.c3
-rw-r--r--src/journal/journalctl.c2
4 files changed, 4 insertions, 5 deletions
diff --git a/src/journal/catalog.c b/src/journal/catalog.c
index 7738d243a5..90ca008064 100644
--- a/src/journal/catalog.c
+++ b/src/journal/catalog.c
@@ -399,7 +399,7 @@ int catalog_update(const char* database, const char* root, const char* const* di
}
assert(n == hashmap_size(h));
- qsort(items, n, sizeof(CatalogItem), catalog_compare_func);
+ qsort_safe(items, n, sizeof(CatalogItem), catalog_compare_func);
r = write_catalog(database, h, sb, items, n);
if (r < 0)
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 78b937bb85..901e71b6aa 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -1344,7 +1344,7 @@ int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const st
/* Order by the position on disk, in order to improve seek
* times for rotating media. */
- qsort(items, n_iovec, sizeof(EntryItem), entry_item_cmp);
+ qsort_safe(items, n_iovec, sizeof(EntryItem), entry_item_cmp);
r = journal_file_append_entry_internal(f, ts, xor_hash, items, n_iovec, seqnum, ret, offset);
diff --git a/src/journal/journal-vacuum.c b/src/journal/journal-vacuum.c
index 8d5effb45c..d4a1c6c933 100644
--- a/src/journal/journal-vacuum.c
+++ b/src/journal/journal-vacuum.c
@@ -299,8 +299,7 @@ int journal_directory_vacuum(
n_list ++;
}
- if (n_list > 0)
- qsort(list, n_list, sizeof(struct vacuum_info), vacuum_compare);
+ qsort_safe(list, n_list, sizeof(struct vacuum_info), vacuum_compare);
for (i = 0; i < n_list; i++) {
struct statvfs ss;
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 2f8be1b83e..275458c482 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -761,7 +761,7 @@ static int get_relative_boot_id(sd_journal *j, sd_id128_t *boot_id, int relative
sd_journal_flush_matches(j);
}
- qsort(all_ids, count, sizeof(boot_id_t), boot_id_cmp);
+ qsort_safe(all_ids, count, sizeof(boot_id_t), boot_id_cmp);
if (sd_id128_equal(*boot_id, SD_ID128_NULL)) {
if (relative > (int) count || relative <= -(int)count)