]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
irqtop: fix numeric sorting
authorValery Ushakov <uwe@stderr.spb.ru>
Wed, 22 Nov 2023 00:56:19 +0000 (03:56 +0300)
committerValery Ushakov <uwe@stderr.spb.ru>
Wed, 22 Nov 2023 00:56:19 +0000 (03:56 +0300)
qsort(3) requires three-way result like that from strcmp(3),
not an std::less like boolean.

sys-utils/irq-common.c

index 725a132814e1579df97e834ddc37caffd8367303..f36ed693c8cbe59113897b8bf728548a2dfdc9a3 100644 (file)
@@ -369,18 +369,29 @@ static inline int cmp_name(const struct irq_info *a,
        return strcoll(a->name, b->name);
 }
 
+static inline int cmp_ulong_descending(unsigned long a,
+                     unsigned long b)
+{
+       if (a == b)
+               return 0;
+       if (a < b)
+               return 1;
+       else
+               return -1;
+}
+
 static inline int cmp_total(const struct irq_info *a,
                      const struct irq_info *b)
 {
-       return a->total < b->total;
+       int cmp = cmp_ulong_descending(a->total, b->total);
+       return cmp ? cmp : cmp_name(a, b);
 }
 
 static inline int cmp_delta(const struct irq_info *a,
                      const struct irq_info *b)
 {
-       if (a->delta != b->delta)
-               return a->delta < b->delta;
-       return cmp_name(a, b);
+       int cmp = cmp_ulong_descending(a->delta, b->delta);
+       return cmp ? cmp : cmp_name(a, b);
 }
 
 static inline int cmp_interrupts(const struct irq_info *a,