diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8331c3c6..94325383 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,7 @@ variables: DEBUG: 'TRUE' SOURCE_FOLDER: "." FLAWFINDER_OPTIONS: "-m 4 --error-level=5" - CPPCHECK_OPTIONS: " --enable=warning --enable=performance --enable=portability --enable=information -DBBFDM_ENABLE_DOTSO_PLUGIN -DBBFDM_ENABLE_DOTSO_PLUGIN -DBBF_TR181 -DBBF_VENDOR_IOPSYS --inline-suppr -i test/" + CPPCHECK_OPTIONS: "--enable=all --suppress=variableScope --suppress=unusedFunction --suppress=constParameter --suppress=knownConditionTrueFalse -DBBF_VENDOR_PREFIX=X_IOPSYS_EU_ -DBBFDM_ENABLE_DOTSO_PLUGIN -DBBFDM_ENABLE_DOTSO_PLUGIN -DBBF_TR181 -DBBF_VENDOR_IOPSYS -i test/" include: - project: 'iopsys/gitlab-ci-pipeline' diff --git a/bbfdmd/ubus/bbfdmd.c b/bbfdmd/ubus/bbfdmd.c index 2ae8100c..5e64bbc5 100644 --- a/bbfdmd/ubus/bbfdmd.c +++ b/bbfdmd/ubus/bbfdmd.c @@ -1036,11 +1036,11 @@ static int bbfdm_service_handler(struct ubus_context *ctx, struct ubus_object *o if (tb[BBF_SERVICE_OBJECTS]) { struct blob_attr *objs = tb[BBF_SERVICE_OBJECTS]; - struct blob_attr *obj = NULL; + struct blob_attr *attr_obj = NULL; size_t rem; - blobmsg_for_each_attr(obj, objs, rem) { - char *srv_obj = blobmsg_get_string(obj); + blobmsg_for_each_attr(attr_obj, objs, rem) { + char *srv_obj = blobmsg_get_string(attr_obj); res |= load_service(DEAMON_DM_ROOT_OBJ, &head_registered_service, srv_name, srv_parent_dm, srv_obj); } } else { @@ -1393,20 +1393,6 @@ static bool register_service(struct ubus_context *ctx) return true; } -bool file_exists(const char *path) -{ - struct stat buffer; - - return stat(path, &buffer) == 0; -} - -bool dir_exists(const char *path) -{ - struct stat buffer; - - return (stat(path, &buffer) == 0 && S_ISDIR(buffer.st_mode)); -} - static int _parse_daemon_config_options(bbfdm_config_t *config, json_object *daemon_obj) { char *opt_val = NULL; @@ -1505,7 +1491,7 @@ static int _fill_daemon_input_option(bbfdm_config_t *config, char *sname) strncpyt(config->in_name, opt_val, sizeof(config->in_name)); snprintf(opt_val, MAX_DM_PATH, "%s/%s", BBFDM_DEFAULT_MICROSERVICE_MODULE_PATH, sname); - if (dir_exists(opt_val)) { + if (folder_exists(opt_val)) { strncpyt(config->in_plugin_dir, opt_val, sizeof(config->in_plugin_dir)); } diff --git a/bbfdmd/ubus/cli.c b/bbfdmd/ubus/cli.c index dda00e6c..d3b2a05e 100644 --- a/bbfdmd/ubus/cli.c +++ b/bbfdmd/ubus/cli.c @@ -103,7 +103,7 @@ static struct blob_attr *get_results_array(struct blob_attr *msg) return tb[0]; } -static void __ubus_callback(struct ubus_request *req, int type __attribute__((unused)), struct blob_attr *msg) +static void __ubus_callback(struct ubus_request *req, int msgtype __attribute__((unused)), struct blob_attr *msg) { struct blob_attr *cur = NULL; int rem = 0; diff --git a/bbfdmd/ubus/pretty_print.c b/bbfdmd/ubus/pretty_print.c index fc207187..fd262e38 100644 --- a/bbfdmd/ubus/pretty_print.c +++ b/bbfdmd/ubus/pretty_print.c @@ -345,7 +345,7 @@ void prepare_result_blob(struct blob_buf *bb, struct list_head *pv_list) return; for (size_t i = 0; i < count; i++) { - struct pvNode *pv = &sortedPV[i]; + pv = &sortedPV[i]; ptr = pv->param; if (list_empty(&result_stack)) { DEBUG("stack empty Processing (%s)", ptr); diff --git a/libbbfdm-api/dmbbf.c b/libbbfdm-api/dmbbf.c index a6b42b14..5ec83ed1 100644 --- a/libbbfdm-api/dmbbf.c +++ b/libbbfdm-api/dmbbf.c @@ -1229,9 +1229,10 @@ static int get_ubus_value(struct dmctx *dmctx, struct dmnode *node) static int get_ubus_supported_dm(struct dmctx *dmctx, struct dmnode *node) { - json_object *res = NULL, *res_obj = NULL; + json_object *res = NULL, *res_obj = NULL, *tmp_obj = NULL; char *ubus_name = node->obj->checkdep; char *in_path = (dmctx->in_param[0] == '\0' || rootcmp(dmctx->in_param, "Device") == 0) ? node->current_object : dmctx->in_param; + char *tmp; json_object *in_args = json_object_new_object(); json_object_object_add(in_args, "proto", json_object_new_string((dmctx->dm_type == BBFDM_BOTH) ? "both" : (dmctx->dm_type == BBFDM_CWMP) ? "cwmp" : "usp")); @@ -1288,10 +1289,10 @@ static int get_ubus_supported_dm(struct dmctx *dmctx, struct dmnode *node) op->in = dmcalloc(in_nbre + 1, sizeof(char *)); for (j = 0; j < in_nbre; j++) { - json_object *res_obj = json_object_array_get_idx(input_array, j); + tmp_obj = json_object_array_get_idx(input_array, j); - char *in_path = dmjson_get_value(res_obj, 1, "path"); - op->in[j] = dmstrdup(in_path); + tmp = dmjson_get_value(tmp_obj, 1, "path"); + op->in[j] = dmstrdup(tmp); } op->in[j] = NULL; } @@ -1303,10 +1304,10 @@ static int get_ubus_supported_dm(struct dmctx *dmctx, struct dmnode *node) op->out = dmcalloc(out_nbre + 1, sizeof(char *)); for (j = 0; j < out_nbre; j++) { - json_object *res_obj = json_object_array_get_idx(output_array, j); + tmp_obj = json_object_array_get_idx(output_array, j); - char *in_path = dmjson_get_value(res_obj, 1, "path"); - op->out[j] = dmstrdup(in_path); + tmp = dmjson_get_value(tmp_obj, 1, "path"); + op->out[j] = dmstrdup(tmp); } op->out[j] = NULL; } @@ -1324,10 +1325,10 @@ static int get_ubus_supported_dm(struct dmctx *dmctx, struct dmnode *node) ev->param = dmcalloc(in_nbre + 1, sizeof(char *)); for (j = 0; j < in_nbre; j++) { - json_object *res_obj = json_object_array_get_idx(input_array, j); + tmp_obj = json_object_array_get_idx(input_array, j); - char *in_path = dmjson_get_value(res_obj, 1, "path"); - ev->param[j] = dmstrdup(in_path); + tmp = dmjson_get_value(tmp_obj, 1, "path"); + ev->param[j] = dmstrdup(tmp); } ev->param[j] = NULL; } diff --git a/libbbfdm-api/dmcommon.c b/libbbfdm-api/dmcommon.c index d519daaa..b37ccbfd 100644 --- a/libbbfdm-api/dmcommon.c +++ b/libbbfdm-api/dmcommon.c @@ -2126,15 +2126,15 @@ char *replace_str(const char *input_str, const char *old_substr, const char *new size_t i = 0; while (*input_str) { - char *match = strstr(input_str, old_substr); - if (match == input_str) { + char *tmp = strstr(input_str, old_substr); + if (tmp == input_str) { // Replace old_substr with new_substr strncpy(&result[i], new_substr, new_substr_len); i += new_substr_len; input_str += old_substr_len; - } else if (match) { + } else if (tmp) { // Copy characters from input_str to result until the match - size_t len = match - input_str; + size_t len = tmp - input_str; strncpy(&result[i], input_str, len); i += len; input_str += len; @@ -2534,7 +2534,7 @@ long upload_file(const char *file_path, const char *url, const char *username, c char dst_path[2046] = {0}; char buff[BUFSIZ] = {0}; FILE *sfp, *dfp; - int n, count=0; + size_t n; sfp = fopen(file_path, "rb"); if (sfp == NULL) { @@ -2550,7 +2550,6 @@ long upload_file(const char *file_path, const char *url, const char *username, c while ((n = fread(buff, 1, BUFSIZ, sfp)) != 0) { fwrite(buff, 1, n, dfp); - count+=n; } fclose(sfp); diff --git a/libbbfdm-api/plugin/json_plugin.c b/libbbfdm-api/plugin/json_plugin.c index 02d8d3d0..0bffa98a 100644 --- a/libbbfdm-api/plugin/json_plugin.c +++ b/libbbfdm-api/plugin/json_plugin.c @@ -1596,11 +1596,11 @@ static int set_value_from_mapping(json_object *param_obj, int json_version, char if (!type_obj) return -1; - char *type = json_object_get_string(type_obj); - if (!type) + char *dm_type = json_object_get_string(type_obj); + if (!dm_type) return -1; - if (DM_LSTRCMP(type, "boolean") == 0) { + if (DM_LSTRCMP(dm_type, "boolean") == 0) { value = dmuci_string_to_boolean(value) ? "1" : "0"; } diff --git a/libbbfdm/dmlayer.c b/libbbfdm/dmlayer.c index 4b149a82..07a39a3b 100644 --- a/libbbfdm/dmlayer.c +++ b/libbbfdm/dmlayer.c @@ -74,7 +74,7 @@ void gre___get_tunnel_system_name(struct uci_section *iface_section, char *devic { char *proto = NULL; - if (!iface_section || !device_str_size || !device_str_size) + if (!iface_section || !device_str_size) return; dmuci_get_value_by_section_string(iface_section, "proto", &proto); @@ -481,7 +481,7 @@ char *ethernet___get_ethernet_interface_name(char *device_name) dmuci_get_value_by_section_string(dev_s, "type", &type); if (DM_STRCMP(type, "8021ad") == 0) { - char *has_vid = DM_STRRCHR(dev_name, '.'); + has_vid = DM_STRRCHR(dev_name, '.'); if (has_vid) *has_vid = '\0'; } diff --git a/libbbfdm/dmtree/tr181/wifi.c b/libbbfdm/dmtree/tr181/wifi.c index dab28b5a..9875bc28 100644 --- a/libbbfdm/dmtree/tr181/wifi.c +++ b/libbbfdm/dmtree/tr181/wifi.c @@ -65,9 +65,9 @@ static inline int init_wifi_radio_power(struct dm_data *curr_data) char *dbm = dmjson_get_value(power, 1, "dbm"); if (!dbm) continue; - int power = (int)strtod(dbm, NULL); + int power_dbm = (int)strtod(dbm, NULL); if (ind < MAX_POWER_INDEX) { - curr_radio_power->transmit_power[ind] = power; + curr_radio_power->transmit_power[ind] = power_dbm; ind++; } }