diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 6c874299ec0f07412ba3e325e84dad218653d5ef..f01d8d328067bb307908d06311dcce3a54aa64ac 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 45dfaa374d1c82836435db70de3c73c24cee7d15..8ff3ee8f751e043f7d10f5a12d3b7f1cc29d1091 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 70d49b7f5693a2ce9a9feebae2ebaf9b90d76443..2f15f64a0dbf6d57abadd379e1cd768e7cd8c76b 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) {