1. fix clang analyzer report bugs; 2. add clean path for all path; Signed-off-by: haozi007 <liuhao27@huawei.com>
209 lines
8.0 KiB
Diff
209 lines
8.0 KiB
Diff
From 348c79c8ee9379f5237d1fdbcdb3678c9a9e9527 Mon Sep 17 00:00:00 2001
|
|
From: haozi007 <liuhao27@huawei.com>
|
|
Date: Tue, 16 Aug 2022 10:23:39 +0800
|
|
Subject: [PATCH 18/21] [clang-analyzer] remove dead assignment
|
|
|
|
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
|
---
|
|
src/cmd/isulad-shim/process.c | 2 +-
|
|
src/cmd/options/opt_log.c | 4 ++++
|
|
src/daemon/executor/container_cb/execution_network.c | 1 -
|
|
src/daemon/modules/image/oci/oci_import.c | 2 --
|
|
src/daemon/modules/image/oci/registry/auths.c | 2 +-
|
|
src/daemon/modules/image/oci/registry/registry.c | 4 +---
|
|
.../graphdriver/overlay2/driver_overlay2.c | 2 +-
|
|
.../image/oci/storage/layer_store/layer_store.c | 12 ++++++++----
|
|
src/daemon/modules/log/log_gather.c | 1 -
|
|
src/daemon/modules/plugin/plugin.c | 1 -
|
|
src/utils/cutils/map/map.c | 2 +-
|
|
src/utils/cutils/path.c | 2 +-
|
|
12 files changed, 18 insertions(+), 17 deletions(-)
|
|
|
|
diff --git a/src/cmd/isulad-shim/process.c b/src/cmd/isulad-shim/process.c
|
|
index 4d665b26..c8ce7a44 100644
|
|
--- a/src/cmd/isulad-shim/process.c
|
|
+++ b/src/cmd/isulad-shim/process.c
|
|
@@ -297,7 +297,7 @@ static void *do_io_copy(void *data)
|
|
}
|
|
|
|
fd_node_t *fn = ioc->fd_to;
|
|
- fd_node_t *next = fn;
|
|
+ fd_node_t *next = NULL;
|
|
for (; fn != NULL; fn = next) {
|
|
next = fn->next;
|
|
if (fn->is_log) {
|
|
diff --git a/src/cmd/options/opt_log.c b/src/cmd/options/opt_log.c
|
|
index 7ec7591f..b1abcfaf 100644
|
|
--- a/src/cmd/options/opt_log.c
|
|
+++ b/src/cmd/options/opt_log.c
|
|
@@ -162,6 +162,10 @@ bool parse_container_log_opt(const char *key, const char *val, json_map_string_s
|
|
}
|
|
nret = append_json_map_string_string(opts, support_parsers[i].real_key, parsed_val);
|
|
free(parsed_val);
|
|
+ if (nret != 0) {
|
|
+ ERROR("Out of memory.");
|
|
+ return false;
|
|
+ }
|
|
return true;
|
|
}
|
|
}
|
|
diff --git a/src/daemon/executor/container_cb/execution_network.c b/src/daemon/executor/container_cb/execution_network.c
|
|
index 6ca79a8c..fa0ec612 100644
|
|
--- a/src/daemon/executor/container_cb/execution_network.c
|
|
+++ b/src/daemon/executor/container_cb/execution_network.c
|
|
@@ -625,7 +625,6 @@ static int merge_resolv(const host_config *host_spec, const char *rootfs, const
|
|
if (ret != 0) {
|
|
WARN("Failed to handle resolv config %s, skip", pline);
|
|
free(tmp_content);
|
|
- ret = 0;
|
|
} else {
|
|
free(content);
|
|
content = tmp_content;
|
|
diff --git a/src/daemon/modules/image/oci/oci_import.c b/src/daemon/modules/image/oci/oci_import.c
|
|
index ae2f547a..335ee8d4 100644
|
|
--- a/src/daemon/modules/image/oci/oci_import.c
|
|
+++ b/src/daemon/modules/image/oci/oci_import.c
|
|
@@ -335,8 +335,6 @@ static int register_image(import_desc *desc)
|
|
ret = -1;
|
|
goto out;
|
|
}
|
|
-
|
|
- ret = 0;
|
|
}
|
|
|
|
image_created = true;
|
|
diff --git a/src/daemon/modules/image/oci/registry/auths.c b/src/daemon/modules/image/oci/registry/auths.c
|
|
index 02b9753c..a95127f2 100644
|
|
--- a/src/daemon/modules/image/oci/registry/auths.c
|
|
+++ b/src/daemon/modules/image/oci/registry/auths.c
|
|
@@ -218,7 +218,7 @@ out:
|
|
free(err);
|
|
err = NULL;
|
|
|
|
- return 0;
|
|
+ return ret;
|
|
}
|
|
|
|
static int add_allocated_auth(registry_auths *auths, char *host, char *auth)
|
|
diff --git a/src/daemon/modules/image/oci/registry/registry.c b/src/daemon/modules/image/oci/registry/registry.c
|
|
index e6369f90..17464c34 100644
|
|
--- a/src/daemon/modules/image/oci/registry/registry.c
|
|
+++ b/src/daemon/modules/image/oci/registry/registry.c
|
|
@@ -696,6 +696,7 @@ static int create_image(pull_descriptor *desc, char *image_id, bool *reuse)
|
|
goto out;
|
|
}
|
|
|
|
+ *reuse = false;
|
|
ret = storage_img_create(image_id, top_layer_id, NULL, &opts);
|
|
if (ret != 0) {
|
|
pre_top_layer = storage_get_img_top_layer(image_id);
|
|
@@ -712,10 +713,7 @@ static int create_image(pull_descriptor *desc, char *image_id, bool *reuse)
|
|
goto out;
|
|
}
|
|
|
|
- ret = 0;
|
|
*reuse = true;
|
|
- } else {
|
|
- *reuse = false;
|
|
}
|
|
|
|
ret = storage_img_add_name(image_id, desc->dest_image_name);
|
|
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c
|
|
index 7a45f880..eac40eb4 100644
|
|
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c
|
|
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c
|
|
@@ -475,7 +475,7 @@ static int do_diff_symlink(const char *id, char *link_id, const char *driver_hom
|
|
}
|
|
|
|
nret = symlink(target_path, clean_path);
|
|
- if (ret < 0) {
|
|
+ if (nret < 0) {
|
|
SYSERROR("Failed to create symlink from \"%s\" to \"%s\"", clean_path, target_path);
|
|
ret = -1;
|
|
goto out;
|
|
diff --git a/src/daemon/modules/image/oci/storage/layer_store/layer_store.c b/src/daemon/modules/image/oci/storage/layer_store/layer_store.c
|
|
index 208bb3bc..cd18c6aa 100644
|
|
--- a/src/daemon/modules/image/oci/storage/layer_store/layer_store.c
|
|
+++ b/src/daemon/modules/image/oci/storage/layer_store/layer_store.c
|
|
@@ -885,12 +885,12 @@ static char *caculate_playload(struct archive *ar)
|
|
break;
|
|
}
|
|
if (r != ARCHIVE_OK) {
|
|
- nret = -1;
|
|
- break;
|
|
+ ERROR("Read archive failed");
|
|
+ goto out;
|
|
}
|
|
if (!isula_crc_update(ctab, &crc, block_buf, block_size)) {
|
|
- nret = -1;
|
|
- break;
|
|
+ ERROR("Do crc update failed");
|
|
+ goto out;
|
|
}
|
|
empty = false;
|
|
}
|
|
@@ -930,6 +930,10 @@ static int archive_entry_parse(struct archive_entry *entry, struct archive *ar,
|
|
sentry.position = position;
|
|
// caculate playload
|
|
sentry.payload = caculate_playload(ar);
|
|
+ if (sentry.payload == NULL) {
|
|
+ ERROR("Caculate playload failed.");
|
|
+ goto out;
|
|
+ }
|
|
|
|
data = storage_entry_generate_json(&sentry, &ctx, &jerr);
|
|
if (data == NULL) {
|
|
diff --git a/src/daemon/modules/log/log_gather.c b/src/daemon/modules/log/log_gather.c
|
|
index 51c112a3..49facaa2 100644
|
|
--- a/src/daemon/modules/log/log_gather.c
|
|
+++ b/src/daemon/modules/log/log_gather.c
|
|
@@ -342,7 +342,6 @@ static int init_log(const struct log_gather_conf *lgconf)
|
|
break;
|
|
case LOG_GATHER_DRIVER_NOSET:
|
|
g_save_log_op = write_into_stdout;
|
|
- driver = LOG_GATHER_DRIVER_STDOUT;
|
|
COMMAND_ERROR("Unset log driver, use stderr to log.");
|
|
break;
|
|
default:
|
|
diff --git a/src/daemon/modules/plugin/plugin.c b/src/daemon/modules/plugin/plugin.c
|
|
index 501271ae..725bca5b 100644
|
|
--- a/src/daemon/modules/plugin/plugin.c
|
|
+++ b/src/daemon/modules/plugin/plugin.c
|
|
@@ -1268,7 +1268,6 @@ int pm_init(void)
|
|
|
|
ret = pthread_rwlock_init(&gpm->pm_rwlock, NULL);
|
|
if (ret != 0) {
|
|
- ret = -1;
|
|
goto bad;
|
|
}
|
|
|
|
diff --git a/src/utils/cutils/map/map.c b/src/utils/cutils/map/map.c
|
|
index 2fe96a54..cca04fe5 100644
|
|
--- a/src/utils/cutils/map/map.c
|
|
+++ b/src/utils/cutils/map/map.c
|
|
@@ -340,7 +340,7 @@ map_t *map_new(map_type_t kvtype, map_cmp_func comparator, map_kvfree_func kvfre
|
|
} else {
|
|
freer = kvfree;
|
|
}
|
|
- cmpor = comparator;
|
|
+
|
|
if (is_key_ptr(kvtype) && (comparator == MAP_DEFAULT_CMP_FUNC)) {
|
|
cmpor = rbtree_ptr_cmp;
|
|
} else if (is_key_int(kvtype) && (comparator == MAP_DEFAULT_CMP_FUNC)) {
|
|
diff --git a/src/utils/cutils/path.c b/src/utils/cutils/path.c
|
|
index 2446f479..79cd7af6 100644
|
|
--- a/src/utils/cutils/path.c
|
|
+++ b/src/utils/cutils/path.c
|
|
@@ -55,7 +55,7 @@ static int do_clean_path(const char *respath, const char *limit_respath, const c
|
|
char *dest = *dst;
|
|
const char *endpos = NULL;
|
|
|
|
- for (endpos = stpos; *stpos; stpos = endpos) {
|
|
+ for (; *stpos; stpos = endpos) {
|
|
while (ISSLASH(*stpos)) {
|
|
++stpos;
|
|
}
|
|
--
|
|
2.25.1
|
|
|