From 0bde77082d8c1efb609646cd0ba222fa46e30487 Mon Sep 17 00:00:00 2001 From: liupan1111 Date: Thu, 29 Sep 2016 04:55:56 +0800 Subject: [PATCH] Fix some cppcheck errors on lib/iscsi & lib/scsi. (#41) Fixed error types: 1 nullPointerRedundantCheck; 2 unsignedLessThanZero; 4 invalidPrintfArgType_sint; 5 arrayIndexThenCheck --- lib/iscsi/conn.c | 3 +- lib/iscsi/iscsi_subsystem.c | 56 +++++++++++++++---------------- lib/iscsi/md5.c | 2 +- lib/scsi/scsi_bdev.c | 3 +- test/lib/bdev/bdevperf/bdevperf.c | 2 +- 5 files changed, 32 insertions(+), 34 deletions(-) diff --git a/lib/iscsi/conn.c b/lib/iscsi/conn.c index 441e9505e..4a794a3ea 100644 --- a/lib/iscsi/conn.c +++ b/lib/iscsi/conn.c @@ -386,8 +386,7 @@ spdk_iscsi_conn_construct(struct spdk_iscsi_portal *portal, SPDK_ERRLOG("iscsi_conn_params_init() failed\n"); error_return: spdk_iscsi_param_free(conn->params); - if (conn) - free_conn(conn); + free_conn(conn); return -1; } conn->is_idle = 0; diff --git a/lib/iscsi/iscsi_subsystem.c b/lib/iscsi/iscsi_subsystem.c index d93f950ed..bdea67e6f 100644 --- a/lib/iscsi/iscsi_subsystem.c +++ b/lib/iscsi/iscsi_subsystem.c @@ -276,42 +276,40 @@ spdk_iscsi_config_dump_target_nodes(FILE *fp) target->map[m].ig->tag); } - if (dev) { - const char *authmethod = "None"; - char authgroup[32] = "None"; - const char *usedigest = "Auto"; + const char *authmethod = "None"; + char authgroup[32] = "None"; + const char *usedigest = "Auto"; - if (target->auth_chap_disabled) - authmethod = "None"; - else if (!target->auth_chap_required) - authmethod = "Auto"; - else if (target->auth_chap_mutual) - authmethod = "CHAP Mutual"; - else - authmethod = "CHAP"; + if (target->auth_chap_disabled) + authmethod = "None"; + else if (!target->auth_chap_required) + authmethod = "Auto"; + else if (target->auth_chap_mutual) + authmethod = "CHAP Mutual"; + else + authmethod = "CHAP"; - if (target->auth_group > 0) - snprintf(authgroup, sizeof(authgroup), "AuthGroup%d", target->auth_group); + if (target->auth_group > 0) + snprintf(authgroup, sizeof(authgroup), "AuthGroup%d", target->auth_group); - if (target->header_digest) - usedigest = "Header"; - else if (target->data_digest) - usedigest = "Data"; + if (target->header_digest) + usedigest = "Header"; + else if (target->data_digest) + usedigest = "Data"; - fprintf(fp, TARGET_NODE_AUTH_TMPL, - authmethod, authgroup, usedigest); + fprintf(fp, TARGET_NODE_AUTH_TMPL, + authmethod, authgroup, usedigest); - for (l = 0; l < dev->maxlun; l++) { - if (NULL == dev->lun[l]) continue; + for (l = 0; l < dev->maxlun; l++) { + if (NULL == dev->lun[l]) continue; - fprintf(fp, TARGET_NODE_LUN_TMPL, - dev->lun[l]->id, - dev->lun[l]->name); - } - - fprintf(fp, TARGET_NODE_QD_TMPL, - target->queue_depth); + fprintf(fp, TARGET_NODE_LUN_TMPL, + dev->lun[l]->id, + dev->lun[l]->name); } + + fprintf(fp, TARGET_NODE_QD_TMPL, + target->queue_depth); } } diff --git a/lib/iscsi/md5.c b/lib/iscsi/md5.c index 86d91c02e..4c6d312a6 100644 --- a/lib/iscsi/md5.c +++ b/lib/iscsi/md5.c @@ -66,7 +66,7 @@ int spdk_md5update(struct spdk_md5ctx *md5ctx, const void *data, size_t len) if (md5ctx == NULL) return -1; - if (data == NULL || len <= 0) + if (data == NULL || len == 0) return 0; rc = MD5_Update(&md5ctx->md5ctx, data, len); return rc; diff --git a/lib/scsi/scsi_bdev.c b/lib/scsi/scsi_bdev.c index 7b405fb31..1b0e1af3d 100644 --- a/lib/scsi/scsi_bdev.c +++ b/lib/scsi/scsi_bdev.c @@ -66,7 +66,8 @@ spdk_bdev_scsi_set_local_naa(char *name, uint8_t *buf) { int i, value, count = 0; uint64_t naa, local_value; - for (i = 0; (name[i] != '\0') && (i < 16); i++) { + + for (i = 0; (i < 16) && (name[i] != '\0'); i++) { value = spdk_hex2bin(name[i]); if (i % 2) { buf[count++] |= value << 4; diff --git a/test/lib/bdev/bdevperf/bdevperf.c b/test/lib/bdev/bdevperf/bdevperf.c index 6011cf3ea..391bbfa89 100644 --- a/test/lib/bdev/bdevperf/bdevperf.c +++ b/test/lib/bdev/bdevperf/bdevperf.c @@ -440,7 +440,7 @@ performance_dump(int io_time) target = head[index]; if (target != NULL) { lcore_id = target->lcore; - printf("\r Logical core: %d\n", lcore_id); + printf("\r Logical core: %u\n", lcore_id); } while (target != NULL) { io_per_second = (float)target->io_completed /