From 7a8a1223ef6ae4be3e54d66dc0650dafb8b5f319 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 25 Aug 2023 17:32:17 -0400 Subject: [PATCH 1/4] writer: Drop dead assignment Spotted by clang-analyzer. Signed-off-by: Colin Walters --- libcomposefs/lcfs-writer.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libcomposefs/lcfs-writer.c b/libcomposefs/lcfs-writer.c index 5842a4b5..b5bcb863 100644 --- a/libcomposefs/lcfs-writer.c +++ b/libcomposefs/lcfs-writer.c @@ -188,8 +188,6 @@ int lcfs_compute_tree(struct lcfs_ctx_s *ctx, struct lcfs_node_s *root) ctx->min_mtim_nsec = root->inode.st_mtim_nsec; ctx->has_acl = false; - node = root; - for (node = root, index = 0; node != NULL; node = node->next, index++) { if ((node->inode.st_mode & S_IFMT) != S_IFDIR && node->children_size != 0) { From 29b9085e7afb136d00727bbd1485d3d9bdf921ed Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 25 Aug 2023 17:40:47 -0400 Subject: [PATCH 2/4] mkcomposefs: Silence an unused variable warning clang-analyzer complains about this. While we're here, make the variable `const`. Signed-off-by: Colin Walters --- tools/mkcomposefs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/mkcomposefs.c b/tools/mkcomposefs.c index 1fb781a6..96df17a9 100644 --- a/tools/mkcomposefs.c +++ b/tools/mkcomposefs.c @@ -569,7 +569,7 @@ int main(int argc, char **argv) cleanup_free char *cwd_cleanup = NULL; cleanup_free char *tmp_pathbuf = NULL; cleanup_free char *absolute_prefix = NULL; - char *cwd = ""; + const char *cwd = ""; int r; if (dir_path[0] != '/') { @@ -578,6 +578,7 @@ int main(int argc, char **argv) error(EXIT_FAILURE, errno, "retrieve current working directory"); } + (void)cwd_cleanup; // This is just used for cleanup r = join_paths(&tmp_pathbuf, cwd, dir_path); if (r < 0) error(EXIT_FAILURE, errno, "compute directory path"); From 4b35a7a2711f553c49bcaee8d216ba82605fbd83 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 25 Aug 2023 17:43:51 -0400 Subject: [PATCH 3/4] mkcomposefs: Switch to declare-and-initialize to silence clang-analyzer clang-analyzer complains about a leak; I think it's wrong, but changing things to atomically initialize the variables silences it. Signed-off-by: Colin Walters --- tools/mkcomposefs.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tools/mkcomposefs.c b/tools/mkcomposefs.c index 96df17a9..1d71e53e 100644 --- a/tools/mkcomposefs.c +++ b/tools/mkcomposefs.c @@ -89,16 +89,13 @@ static int ensure_dir(const char *path, mode_t mode) static int mkdir_parents(const char *pathname, int mode) { - cleanup_free char *fn = NULL; - char *p; - - fn = strdup(pathname); + cleanup_free char *fn = strdup(pathname); if (fn == NULL) { errno = ENOMEM; return -1; } - p = fn; + char *p = fn; while (*p == '/') p++; From 9e46d052d97726bea1844b5eb8873072386e7537 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 25 Aug 2023 17:46:13 -0400 Subject: [PATCH 4/4] mkcomposefs: Fix possibly garbage return in error path Found by clang-analyzer. (At this point, I have to say: I don't understand why in 2021 we created a new project in the C programming language...) Signed-off-by: Colin Walters --- tools/mkcomposefs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/mkcomposefs.c b/tools/mkcomposefs.c index 1d71e53e..c67bba80 100644 --- a/tools/mkcomposefs.c +++ b/tools/mkcomposefs.c @@ -319,7 +319,7 @@ static int fill_payload(struct lcfs_node_s *node, const char *path, size_t len, char target[PATH_MAX + 1]; ssize_t s = readlink(path, target, sizeof(target)); if (s < 0) - return ret; + return s; target[s] = '\0'; ret = lcfs_node_set_payload(node, target);