From: Valery Ushakov Date: Wed, 22 Nov 2023 00:56:19 +0000 (+0300) Subject: irqtop: fix numeric sorting X-Git-Tag: v2.40-rc1~152^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=65ca5080159444e25b13e092678bf84164f9de6e;p=thirdparty%2Futil-linux.git irqtop: fix numeric sorting qsort(3) requires three-way result like that from strcmp(3), not an std::less like boolean. --- diff --git a/sys-utils/irq-common.c b/sys-utils/irq-common.c index 725a132814..f36ed693c8 100644 --- a/sys-utils/irq-common.c +++ b/sys-utils/irq-common.c @@ -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,