daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
65878a
From 50f0e2315d0c22d2e98e53ff02e7ae2412463e9a Mon Sep 17 00:00:00 2001
65878a
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
65878a
Date: Mon, 14 Oct 2013 19:15:24 -0400
65878a
Subject: [PATCH] Fix bad assert in show_pid_array
65878a
65878a
This function should get the same treatment as other qsort uses
65878a
did in 7ff7394 "Never call qsort on potentially NULL arrays".
65878a
65878a
Reported-by: Oleksii Shevchuk <alxchk@gmail.com>
65878a
---
65878a
 src/shared/cgroup-show.c | 4 +---
65878a
 1 file changed, 1 insertion(+), 3 deletions(-)
65878a
65878a
diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c
65878a
index cc44ab4..aa0f017 100644
65878a
--- a/src/shared/cgroup-show.c
65878a
+++ b/src/shared/cgroup-show.c
65878a
@@ -44,8 +44,6 @@ static void show_pid_array(int pids[], unsigned n_pids, const char *prefix, unsi
65878a
         unsigned i, m, pid_width;
65878a
         pid_t biggest = 0;
65878a
 
65878a
-        assert(n_pids > 0);
65878a
-
65878a
         /* Filter duplicates */
65878a
         m = 0;
65878a
         for (i = 0; i < n_pids; i++) {
65878a
@@ -65,7 +63,7 @@ static void show_pid_array(int pids[], unsigned n_pids, const char *prefix, unsi
65878a
         pid_width = DECIMAL_STR_WIDTH(biggest);
65878a
 
65878a
         /* And sort */
65878a
-        qsort(pids, n_pids, sizeof(pid_t), compare);
65878a
+        qsort_safe(pids, n_pids, sizeof(pid_t), compare);
65878a
 
65878a
         if(flags & OUTPUT_FULL_WIDTH)
65878a
                 n_columns = 0;