Skip to content

Commit

Permalink
DAOS-6685 Test: Fixed coverity issue in test code.
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 committed Feb 18, 2021
1 parent 13375a5 commit 2299998
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/common/tests_dmg_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,13 +583,8 @@ parse_device_info(struct json_object *smd_dev, device_list *devices,
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);
return -DER_INVAL;
}
strncpy(devices[*disks].host, strtok(host, ":") + 1,
sizeof(devices[*disks].host) - 1);

if (!json_object_object_get_ex(dev, "uuid", &tmp)) {
D_ERROR("unable to extract uuid from JSON\n");
Expand All @@ -615,7 +610,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));

strncpy(devices[*disks].state, json_object_to_json_string(tmp),
sizeof(devices[*disks].state) - 1);

if (!json_object_object_get_ex(dev, "rank", &tmp)) {
D_ERROR("unable to extract rank from JSON\n");
Expand Down Expand Up @@ -656,19 +653,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 +679,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 +707,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 2299998

Please sign in to comment.