commit:     e01850fc012cc7b3ce66b4f6670aa31868ec1427
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Tue Aug 19 14:11:14 2025 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Tue Aug 19 14:11:14 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=e01850fc

*: fix coverity issues and GCC warnings

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

 libq/copy_file.c |  3 ++-
 libq/tree.c      | 10 ++++++++--
 libq/xpak.c      |  7 +++++--
 main.c           |  4 ++--
 qgrep.c          |  2 +-
 qlop.c           |  8 ++++----
 6 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/libq/copy_file.c b/libq/copy_file.c
index 955fd78..36c4e18 100644
--- a/libq/copy_file.c
+++ b/libq/copy_file.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2021 Gentoo Foundation
+ * Copyright 2005-2025 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2011-2016 Mike Frysinger  - <[email protected]>
@@ -57,6 +57,7 @@ int copy_file_fd(int fd_src, int fd_dst)
                if (offset == (off_t)len)
                        return 0;
 #endif
+               (void)ret;  /* ignore ret, we fall back */
 
                /* fall back to read/write, rewind the fd */
                lseek(fd_src, 0, SEEK_SET);

diff --git a/libq/tree.c b/libq/tree.c
index abce6f4..963785b 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -327,8 +327,14 @@ tree_next_cat(tree_ctx *ctx)
                                                        (int (*)(const void *, 
const void *))alphasort);
                                free(cats);
                        } else {
-                               ctx->cat_cnt = scandirat(ctx->tree_fd,
-                                               ".", &ctx->cat_de, 
tree_filter_cat, alphasort);
+                               int sdret = scandirat(ctx->tree_fd, ".",
+                                                                         
&ctx->cat_de,
+                                                                         
tree_filter_cat, alphasort);
+                               /* CID 548426 */
+                               if (sdret < 0)
+                                       ctx->cat_cnt = 0;
+                               else
+                                       ctx->cat_cnt = (size_t)sdret;
                        }
                        ctx->cat_cur = 0;
                }

diff --git a/libq/xpak.c b/libq/xpak.c
index 0e8bd7e..300d1ff 100644
--- a/libq/xpak.c
+++ b/libq/xpak.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2020 Gentoo Foundation
+ * Copyright 2005-2025 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <[email protected]>
@@ -299,7 +299,7 @@ xpak_create(
                int verbose)
 {
        FILE *findex, *fdata, *fout;
-       struct dirent **dir;
+       struct dirent **dir = NULL;
        int i, fidx, numfiles;
        struct stat st;
        char path[_Q_PATH_MAX];
@@ -342,7 +342,10 @@ xpak_create(
                if (S_ISDIR(st.st_mode)) {
                        if ((numfiles =
                                                scandir(argv[i], &dir, 
filter_hidden, alphasort)) < 0)
+                       {
                                warn("Directory '%s' is empty; skipping", 
argv[i]);
+                               continue;
+                       }
                        for (fidx = 0; fidx < numfiles; ++fidx) {
                                int ret = snprintf(path, sizeof(path), "%s/%s",
                                                argv[i], dir[fidx]->d_name);

diff --git a/main.c b/main.c
index 511fb3c..676988c 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2024 Gentoo Foundation
+ * Copyright 2005-2025 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2008 Ned Ludd        - <[email protected]>
@@ -428,7 +428,7 @@ static void
 read_portage_file(const char *file, enum portage_file_type type, void *data)
 {
        FILE *fp;
-       struct dirent **dents;
+       struct dirent **dents = NULL;
        int dentslen;
        char *s;
        char *p;

diff --git a/qgrep.c b/qgrep.c
index 51c2a07..ccb4d5a 100644
--- a/qgrep.c
+++ b/qgrep.c
@@ -589,7 +589,7 @@ int qgrep_main(int argc, char **argv)
                args.portdir = overlay;
                if (do_eclass) {
                        char buf[_Q_PATH_MAX];
-                       char name[_Q_PATH_MAX];
+                       char name[_Q_PATH_MAX + 8 /* colours/eclass */];
                        char *label;
                        int efd;
 

diff --git a/qlop.c b/qlop.c
index 1e45c88..93daf20 100644
--- a/qlop.c
+++ b/qlop.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2023 Gentoo Foundation
+ * Copyright 2005-2025 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd        - <[email protected]>
@@ -1369,14 +1369,14 @@ static int do_emerge_log(
  * or root */
 static array_t *probe_proc(array_t *atoms)
 {
-       struct dirent **procs;
+       struct dirent **procs = NULL;
        int procslen;
        int pi;
-       struct dirent **links;
+       struct dirent **links = NULL;
        int linkslen;
        int li;
        struct dirent *d;
-       char npath[_Q_PATH_MAX * 2];
+       char npath[(_Q_PATH_MAX * 2) + 16];
        char rpath[_Q_PATH_MAX];
        const char *subdir = NULL;
        const char *pid;

Reply via email to