Fix some cppcheck errors on lib/iscsi & lib/scsi. (#41)

Fixed error types:
 1 nullPointerRedundantCheck;
 2 unsignedLessThanZero;
 4 invalidPrintfArgType_sint;
 5 arrayIndexThenCheck
This commit is contained in:
liupan1111 2016-09-29 04:55:56 +08:00 committed by Daniel Verkamp
parent e445f16bac
commit 0bde77082d
5 changed files with 32 additions and 34 deletions

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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 /