commit: 067af6b9098858e786e71ef20cb91ad75c6e4ba4
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Tue Feb 7 08:24:21 2023 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Tue Feb 7 08:24:21 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=067af6b9
set: try to silence Coverity
Now add_set_value can allocate a new set, Coverity thinks this will
actually happen, despite in these cases the input set not being NULL.
Help Coverity by adding a redundant if.
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
libq/tree.c | 3 ++-
main.c | 12 +++++++++---
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/libq/tree.c b/libq/tree.c
index a05a86e..f308c8d 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1709,7 +1709,8 @@ tree_match_atom_cache_populate_cb(tree_pkg_ctx *ctx, void
*priv)
cat_ctx = get_set(atom->CATEGORY, cache);
if (cat_ctx == NULL) {
cat_ctx = tree_open_cat(tctx, ".");
- cache = add_set_value(atom->CATEGORY, cat_ctx, NULL, cache);
+ if (cache != NULL) /* for static code analysers */
+ add_set_value(atom->CATEGORY, cat_ctx, NULL, cache);
/* get a pointer from the set */
cat_ctx->name = contains_set(atom->CATEGORY, cache);
}
diff --git a/main.c b/main.c
index c5b27fe..884d6da 100644
--- a/main.c
+++ b/main.c
@@ -585,9 +585,15 @@ read_portage_file(const char *file, enum portage_file_type
type, void *data)
snprintf(npath, sizeof(npath), "%s:%zu:%zu-%zu",
file, line, cbeg, cend);
p = xstrdup(npath);
- masks = add_set_value(buf, p, &e, masks);
- if (e != NULL)
- free(p);
+ /* if not necessary, but do it for static code
analysers
+ * which take into accound that add_set_value
might
+ * allocate a new set when masks would be NULL
-- a case
+ * which would never happen */
+ if (masks != NULL) {
+ add_set_value(buf, p, &e, masks);
+ if (e != NULL)
+ free(p);
+ }
}
}
}