commit:     e05b6baf296397bc2a10dad728f2840ab242b833
Author:     Pavel Kalugin <pavel <AT> pavelthebest <DOT> me>
AuthorDate: Tue Dec 12 19:32:35 2023 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sat Jan 27 13:27:30 2024 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=e05b6baf

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 <pavel <AT> pavelthebest.me>
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 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;

Reply via email to