From e3d608e4bacd367fed99bcdd7f56b3fba7b02891 Mon Sep 17 00:00:00 2001 From: vdutta <vivek.dutta@iopsys.eu> Date: Tue, 25 Jan 2022 17:02:05 +0530 Subject: [PATCH] Fix static code analysis errors --- .gitlab-ci.yml | 1 + src/qosmngr.c | 15 +++++++++------ test/cmocka/functional_test_qos.c | 3 +-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6c87429..f01d8d3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,6 +11,7 @@ stages: variables: DEBUG: 'TRUE' SOURCE_FOLDER: "." + RUN_CPPCHECK: "cppcheck --enable=all --error-exitcode=1 ${SOURCE_FOLDER}" run_api_test: stage: api_test diff --git a/src/qosmngr.c b/src/qosmngr.c index 45dfaa3..8ff3ee8 100644 --- a/src/qosmngr.c +++ b/src/qosmngr.c @@ -263,13 +263,14 @@ static int prepare_stats_blob(struct blob_buf *b, struct qos_stats *stats, void static int get_stats_by_ifname(struct blob_buf *b, struct qos_stats *stats, void *dd, char *ifname, int qid) { - int queues = 0; - int i, ret = 0; + int ret = 0; if (qid >= 0) { ret = prepare_stats_blob(b, stats, dd, ifname, qid); } else { - queues = get_no_queues(ifname); + int i; + int queues = get_no_queues(ifname); + for (i = 0; i < queues; i++) { ret = prepare_stats_blob(b, stats, dd, ifname, i); if (ret != 0) @@ -332,17 +333,19 @@ static int validate_keys(char *req_json) int len = strlen(req_json); for (i = 0; i < len; i++) { - char key[IFNAMSIZ] = {0}; if (req_json[i] == QUOTE) { + char key[IFNAMSIZ] = {0}; int j = 0; i++; - while (req_json[i] != QUOTE) { + + while ((i < len) && (req_json[i] != QUOTE)) { key[j] = req_json[i]; j++; i++; } i++; - while ((req_json[i] != SEPERATOR) && (i < len)) + + while ((i < len) && (req_json[i] != SEPERATOR)) i++; if (!(!strncmp(key, PARAM1, strlen(PARAM1)) || diff --git a/test/cmocka/functional_test_qos.c b/test/cmocka/functional_test_qos.c index 70d49b7..2f15f64 100644 --- a/test/cmocka/functional_test_qos.c +++ b/test/cmocka/functional_test_qos.c @@ -77,7 +77,6 @@ static void validate_queues(struct json_object *queues) { int i; int len; - struct json_object *queue; assert_non_null(queues); len = json_object_array_length(queues); @@ -86,7 +85,7 @@ static void validate_queues(struct json_object *queues) assert_true(len >= 0); for (i = 0; i < len; i++) { - queue = json_object_array_get_idx(queues, i); + struct json_object *queue = json_object_array_get_idx(queues, i); json_object_object_foreach(queue, key, val) { int val_type = json_object_get_type(val); switch(val_type) { -- GitLab