commit:     a7ffe6b97fb12e065a0a8079530b06260501310f
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 26 19:04:00 2026 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon Jan 26 19:49:51 2026 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=a7ffe6b9

libq/array: ensure we don't try to deal with NULL pointer, CID 557214

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/array.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libq/array.c b/libq/array.c
index 69eb9624..e7be9e43 100644
--- a/libq/array.c
+++ b/libq/array.c
@@ -205,10 +205,12 @@ void array_sort
 )
 {
   if (arr != NULL &&
-      arr->len > 1 &&
       !arr->sorted)
-    qsort(arr->eles, arr->len, sizeof(void *), compar);
-  arr->sorted = true;
+  {
+    if (arr->len > 1)
+      qsort(arr->eles, arr->len, sizeof(void *), compar);
+    arr->sorted = true;
+  }
 }
 
 /* binary search over the array, returning the first element for which

Reply via email to