Skip to content

Commit

Permalink
Addressing more feedback on PR
Browse files Browse the repository at this point in the history
Doing further code cleanup based on feedback on PR. This commit should
be squashed before this is merged.

Signed-off-by: Brian Atkinson <[email protected]>
  • Loading branch information
bwatkinson committed Mar 20, 2024
1 parent 7274cc3 commit 4de1e35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/client/parse_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ xddfunc_datapattern(xdd_plan_t *planp, int32_t argc, char *argv[], uint32_t flag
}
tdp->td_dpp->data_pattern_length = stat_buf.st_size;
if(xdd_set_datapattern_from_filename(tdp, argv[args+2])) {
return (0);
return(0);
}
} else {// Put this option into all Targets
if (flags & XDD_PARSE_PHASE2) {
Expand All @@ -591,7 +591,7 @@ xddfunc_datapattern(xdd_plan_t *planp, int32_t argc, char *argv[], uint32_t flag
dp_fd = open(argv[args+2], O_RDONLY);
if (dp_fd < 0) {
fprintf(xgp->errout, "%s: could not open %s\n", xgp->progname, argv[args+2]);
return (0);
return(0);
}
if (strcmp(pattern_type, "file") == 0) {
tdp->td_dpp->data_pattern_options |= DP_FILE_PATTERN;
Expand All @@ -604,7 +604,7 @@ xddfunc_datapattern(xdd_plan_t *planp, int32_t argc, char *argv[], uint32_t flag
while (tdp) {
if (xdd_set_datapattern_from_file_descriptor(tdp, dp_fd, argv[args+2])) {
close(dp_fd);
return (0);
return(0);
}
i++;
tdp = planp->target_datap[i];
Expand Down
12 changes: 5 additions & 7 deletions src/common/datapatterns.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ xdd_set_datapattern_from_filename(target_data_t *tdp, char *filename) {

dp->data_pattern_filename = filename;
ret = xdd_set_datapattern_from_file_descriptor(tdp, fd, filename);
close (fd);
close(fd);

return ret;
} // End of xdd_set_datapattern_from_filename()
Expand Down Expand Up @@ -328,20 +328,18 @@ xdd_set_datapattern_from_file_descriptor(target_data_t *tdp, int fd, char *filen
goto error;
}

memset(dp->data_pattern, '\0', sizeof(unsigned char) * dp->data_pattern_length + 1);
ssize_t bytes = pread(fd, dp->data_pattern, dp->data_pattern_length, 0);
size_t bytes = pread(fd, dp->data_pattern, dp->data_pattern_length, 0);
if (bytes != dp->data_pattern_length) {
fprintf(xgp->errout, "%s: short read from file %s when setting target datapattern. "
"Espected %d bytes but got %d",
"Espected %zu bytes but got %zu",
xgp->progname, filename, dp->data_pattern_length, bytes);
goto error;
}

return 0;

error:
if (dp->data_pattern) {
free(dp->data_pattern);
}
free(dp->data_pattern);
return 1;
} // End of xdd_set_datapattern_from_file_descriptor()

Expand Down

0 comments on commit 4de1e35

Please sign in to comment.