Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAOS-6685 Test: Fixed coverity issue in test code. #4684

Merged
merged 5 commits into from
Feb 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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