From e05b6baf296397bc2a10dad728f2840ab242b833 Mon Sep 17 00:00:00 2001 From: Pavel Kalugin Date: Tue, 12 Dec 2023 22:32:35 +0300 Subject: libq/atom: fix atom comparison bug qlop SEGFAULTed when predict on a package without category was called Closes: https://github.com/gentoo/portage-utils/pull/24 Signed-off-by: Pavel Kalugin Signed-off-by: Fabian Groffen --- libq/atom.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libq/atom.c b/libq/atom.c index 31299f1..b1a150a 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -1252,7 +1252,15 @@ atom_compar_cb(const void *l, const void *r) default: { int ret; - ret = strcmp(al->CATEGORY, ar->CATEGORY); + if (!al->CATEGORY && !ar->CATEGORY) { + ret = 0; + } else if (!al->CATEGORY) { + ret = -1; + } else if (!ar->CATEGORY) { + ret = 1; + } else { + ret = strcmp(al->CATEGORY, ar->CATEGORY); + } if (ret == 0) ret = strcasecmp(al->PN, ar->PN); return ret; -- cgit v1.2.3-65-gdbad