From 282ca370500f76e6d9906e28c881350857d45f8f Mon Sep 17 00:00:00 2001 From: eeff <33566201+eeff@users.noreply.github.com> Date: Mon, 4 Jul 2022 22:46:53 +0800 Subject: [PATCH] ci: remove cppcheck errors --- plugins/ekuiper/json_rw.c | 6 ++---- plugins/restful/http.c | 7 ++++--- src/parser/neu_json_group_config.c | 20 +++++-------------- src/parser/neu_json_license.c | 7 ++++--- src/parser/neu_json_login.c | 4 +--- src/parser/neu_json_node.c | 20 +++++-------------- src/parser/neu_json_plugin.c | 8 ++------ src/parser/neu_json_rw.c | 8 ++------ src/persist/json/persist_json_group_configs.c | 4 +--- src/persist/persist.c | 2 +- 10 files changed, 27 insertions(+), 59 deletions(-) diff --git a/plugins/ekuiper/json_rw.c b/plugins/ekuiper/json_rw.c index aad573ea..7a66b634 100644 --- a/plugins/ekuiper/json_rw.c +++ b/plugins/ekuiper/json_rw.c @@ -141,7 +141,7 @@ int json_encode_read_resp_tags(void *json_object, void *param) return -1; } errors_object = neu_json_encode_new(); - if (NULL == values_object) { + if (NULL == errors_object) { plog_error(plugin, "ekuiper cannot allocate json object"); json_decref(values_object); return -1; @@ -260,9 +260,7 @@ int json_decode_write_req(char *buf, size_t len, json_write_req_t **result) goto decode_exit; decode_fail: - if (req != NULL) { - free(req); - } + free(req); ret = -1; decode_exit: diff --git a/plugins/restful/http.c b/plugins/restful/http.c index 3a3cfc48..336f99a0 100644 --- a/plugins/restful/http.c +++ b/plugins/restful/http.c @@ -62,8 +62,9 @@ static int response(nng_aio *aio, char *content, enum nng_http_status status) ssize_t url_decode(const char *s, size_t len, char *buf, size_t size) { - size_t i = 0, j = 0; - int c = 0, n = 0; + size_t i = 0, j = 0; + int n = 0; + unsigned int c; while (i < len && j < size) { c = s[i++]; if ('+' == c) { @@ -92,7 +93,7 @@ int http_get_body(nng_aio *aio, void **data, size_t *data_size) nng_http_req *req = nng_aio_get_input(aio, 0); nng_http_req_get_data(req, data, data_size); - if (*data_size <= 0) { + if (*data_size == 0) { return -1; } else { char *buf = calloc(*data_size + 1, sizeof(char)); diff --git a/src/parser/neu_json_group_config.c b/src/parser/neu_json_group_config.c index 9559c04f..4aa4d48d 100644 --- a/src/parser/neu_json_group_config.c +++ b/src/parser/neu_json_group_config.c @@ -68,9 +68,7 @@ int neu_json_decode_add_group_config_req( goto decode_exit; decode_fail: - if (req != NULL) { - free(req); - } + free(req); ret = -1; decode_exit: @@ -123,9 +121,7 @@ int neu_json_decode_del_group_config_req( goto decode_exit; decode_fail: - if (req != NULL) { - free(req); - } + free(req); ret = -1; decode_exit: @@ -260,9 +256,7 @@ int neu_json_decode_subscribe_req(char *buf, neu_json_subscribe_req_t **result) goto decode_exit; decode_fail: - if (req != NULL) { - free(req); - } + free(req); ret = -1; decode_exit: @@ -320,9 +314,7 @@ int neu_json_decode_unsubscribe_req(char * buf, goto decode_exit; decode_fail: - if (req != NULL) { - free(req); - } + free(req); ret = -1; decode_exit: @@ -381,9 +373,7 @@ int neu_json_decode_update_group_config_req( goto decode_exit; decode_fail: - if (req != NULL) { - free(req); - } + free(req); ret = -1; decode_exit: diff --git a/src/parser/neu_json_license.c b/src/parser/neu_json_license.c index 80d36b75..693df53a 100644 --- a/src/parser/neu_json_license.c +++ b/src/parser/neu_json_license.c @@ -101,6 +101,9 @@ int neu_json_decode_set_license_req(char * buf, int ret = 0; neu_json_set_license_req_t *req = calloc(1, sizeof(neu_json_set_license_req_t)); + if (NULL == req) { + return -1; + } neu_json_elem_t req_elems[] = { { .name = "license", @@ -117,9 +120,7 @@ int neu_json_decode_set_license_req(char * buf, return ret; decode_fail: - if (req != NULL) { - free(req); - } + free(req); return -1; } diff --git a/src/parser/neu_json_login.c b/src/parser/neu_json_login.c index 93c4049e..dc2c01e8 100644 --- a/src/parser/neu_json_login.c +++ b/src/parser/neu_json_login.c @@ -54,9 +54,7 @@ int neu_json_decode_login_req(char *buf, neu_json_login_req_t **result) return ret; decode_fail: - if (req != NULL) { - free(req); - } + free(req); return -1; } diff --git a/src/parser/neu_json_node.c b/src/parser/neu_json_node.c index cdff0eb8..f72793c9 100644 --- a/src/parser/neu_json_node.c +++ b/src/parser/neu_json_node.c @@ -61,9 +61,7 @@ int neu_json_decode_add_node_req(char *buf, neu_json_add_node_req_t **result) goto decode_exit; decode_fail: - if (req != NULL) { - free(req); - } + free(req); ret = -1; decode_exit: @@ -109,9 +107,7 @@ int neu_json_decode_del_node_req(char *buf, neu_json_del_node_req_t **result) goto decode_exit; decode_fail: - if (req != NULL) { - free(req); - } + free(req); ret = -1; decode_exit: @@ -219,9 +215,7 @@ int neu_json_decode_update_node_req(char * buf, goto decode_exit; decode_fail: - if (req != NULL) { - free(req); - } + free(req); ret = -1; decode_exit: @@ -271,9 +265,7 @@ int neu_json_decode_node_ctl_req(char *buf, neu_json_node_ctl_req_t **result) goto decode_exit; decode_fail: - if (req != NULL) { - free(req); - } + free(req); ret = -1; decode_exit: @@ -318,9 +310,7 @@ int neu_json_decode_node_setting_req(char * buf, goto decode_exit; decode_fail: - if (req != NULL) { - free(req); - } + free(req); ret = -1; decode_exit: diff --git a/src/parser/neu_json_plugin.c b/src/parser/neu_json_plugin.c index d2b8c646..61a6f2b8 100644 --- a/src/parser/neu_json_plugin.c +++ b/src/parser/neu_json_plugin.c @@ -58,9 +58,7 @@ int neu_json_decode_add_plugin_req(char * buf, goto decode_exit; decode_fail: - if (req != NULL) { - free(req); - } + free(req); ret = -1; decode_exit: @@ -107,9 +105,7 @@ int neu_json_decode_del_plugin_req(char * buf, goto decode_exit; decode_fail: - if (req != NULL) { - free(req); - } + free(req); ret = -1; decode_exit: diff --git a/src/parser/neu_json_rw.c b/src/parser/neu_json_rw.c index 482d3cc8..7e624b0e 100644 --- a/src/parser/neu_json_rw.c +++ b/src/parser/neu_json_rw.c @@ -157,9 +157,7 @@ int neu_json_decode_write_req(char *buf, neu_json_write_req_t **result) goto decode_exit; decode_fail: - if (req != NULL) { - free(req); - } + free(req); ret = -1; decode_exit: @@ -213,9 +211,7 @@ int neu_json_decode_read_req(char *buf, neu_json_read_req_t **result) goto decode_exit; decode_fail: - if (req != NULL) { - free(req); - } + free(req); ret = -1; decode_exit: diff --git a/src/persist/json/persist_json_group_configs.c b/src/persist/json/persist_json_group_configs.c index cefb6f61..847a71ad 100644 --- a/src/persist/json/persist_json_group_configs.c +++ b/src/persist/json/persist_json_group_configs.c @@ -68,9 +68,7 @@ int neu_json_decode_group_configs_req(char * buf, goto decode_exit; decode_fail: - if (req != NULL) { - free(req); - } + free(req); ret = -1; decode_exit: diff --git a/src/persist/persist.c b/src/persist/persist.c index 0802a49b..52bd0605 100644 --- a/src/persist/persist.c +++ b/src/persist/persist.c @@ -103,7 +103,7 @@ const char *neu_persister_get_plugins_fname(neu_persister_t *persister) static int path_escape(char *buf, size_t size, const char *path) { size_t i = 0; - char c = '\0'; + char c; if (NULL != buf) { for (const char *s = path; (c = *s++) && i < size; ++i) {