Skip to content

Commit

Permalink
DAOS-6685 Test: Fixed coverity issue in test code. (#4684)
Browse files Browse the repository at this point in the history
Fixed Coverity issue in test code.
313028(#2 of 2) and 313033(#1 of 1).

Signed-off-by: Samir Raval <[email protected]>
  • Loading branch information
ravalsam authored Feb 26, 2021
1 parent 3041fca commit b0ac09c
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/common/tests_dmg_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,18 +579,20 @@ parse_device_info(struct json_object *smd_dev, device_list *devices,
struct json_object *targets;
int tgts_len;
int i, j;
char *tmp_var;

for (i = 0; i < dev_length; i++) {
dev = json_object_array_get_idx(smd_dev, i);

if (strlen(host + 2) <= DSS_HOSTNAME_MAX_LEN)
strcpy(devices[*disks].host, strtok(host, ":") + 1);
else {
D_ERROR("Hostname is larger than %d\n",
DSS_HOSTNAME_MAX_LEN);
tmp_var = strtok(host, ":");
if (tmp_var == NULL) {
D_ERROR("Hostname is empty\n");
return -DER_INVAL;
}

snprintf(devices[*disks].host, sizeof(devices[*disks].host),
"%s", tmp_var + 1);

if (!json_object_object_get_ex(dev, "uuid", &tmp)) {
D_ERROR("unable to extract uuid from JSON\n");
return -DER_INVAL;
Expand All @@ -615,7 +617,9 @@ parse_device_info(struct json_object *smd_dev, device_list *devices,
D_ERROR("unable to extract state from JSON\n");
return -DER_INVAL;
}
strcpy(devices[*disks].state, json_object_to_json_string(tmp));

snprintf(devices[*disks].state, sizeof(devices[*disks].state),
"%s", json_object_to_json_string(tmp));

if (!json_object_object_get_ex(dev, "rank", &tmp)) {
D_ERROR("unable to extract rank from JSON\n");
Expand Down Expand Up @@ -656,19 +660,17 @@ dmg_storage_device_list(const char *dmg_config_file, int *ndisks,

if (!json_object_object_get_ex(dmg_out, "host_storage_map",
&storage_map)) {
D_FREE(disk);
D_ERROR("unable to extract host_storage_map from JSON\n");
return -DER_INVAL;
D_GOTO(out, rc = -DER_INVAL);
}

json_object_object_foreach(storage_map, key, val) {
D_DEBUG(DB_TEST, "key:\"%s\",val=%s\n", key,
json_object_to_json_string(val));

if (!json_object_object_get_ex(val, "hosts", &hosts)) {
D_FREE(disk);
D_ERROR("unable to extract hosts from JSON\n");
return -DER_INVAL;
D_GOTO(out, rc = -DER_INVAL);
}

D_ALLOC(host, strlen(json_object_to_json_string(hosts)) + 1);
Expand All @@ -684,7 +686,7 @@ dmg_storage_device_list(const char *dmg_config_file, int *ndisks,
smd_info, "devices", &smd_dev)) {
D_ERROR("unable to extract devices\n");
D_FREE(host);
return -DER_INVAL;
D_GOTO(out, rc = -DER_INVAL);
}

if (smd_dev != NULL)
Expand Down Expand Up @@ -712,6 +714,7 @@ dmg_storage_device_list(const char *dmg_config_file, int *ndisks,
if (dmg_out != NULL)
json_object_put(dmg_out);

out:
D_FREE(disk);
return rc;
}
Expand Down

0 comments on commit b0ac09c

Please sign in to comment.