Commit b5a2087b authored by Philip Carns's avatar Philip Carns

clean up string handling in darshan_log_put_mounts()

parent 2becd2dc
...@@ -477,27 +477,32 @@ int darshan_log_put_mounts(darshan_fd fd, struct darshan_mnt_info *mnt_data_arra ...@@ -477,27 +477,32 @@ int darshan_log_put_mounts(darshan_fd fd, struct darshan_mnt_info *mnt_data_arra
{ {
struct darshan_fd_int_state *state = fd->state; struct darshan_fd_int_state *state = fd->state;
int i; int i;
char line[1024];
char mnt_dat[DARSHAN_EXE_LEN] = {0}; char mnt_dat[DARSHAN_EXE_LEN] = {0};
int mnt_dat_sz = 0;
char *tmp;
int ret; int ret;
int left = DARSHAN_EXE_LEN;
int pos = 0;
assert(state); assert(state);
/* write each mount entry to file */ /* write each mount entry to file */
tmp = mnt_dat;
for(i=count-1; i>=0; i--) for(i=count-1; i>=0; i--)
{ {
sprintf(line, "\n%s\t%s", mnt_data_array[i].mnt_type, mnt_data_array[i].mnt_path); if((strlen(mnt_data_array[i].mnt_type) + strlen(mnt_data_array[i].mnt_path) + 2) < left)
{
memcpy(tmp, line, strlen(line)); ret = snprintf(&mnt_dat[pos], left, "\n%s\t%s", mnt_data_array[i].mnt_type, mnt_data_array[i].mnt_path);
tmp += strlen(line); left -= ret;
mnt_dat_sz += strlen(line); assert(left >= 0);
pos += ret;
}
else
{
break;
} }
}
pos++;
ret = darshan_log_dzwrite(fd, DARSHAN_JOB_REGION_ID, mnt_dat, mnt_dat_sz); ret = darshan_log_dzwrite(fd, DARSHAN_JOB_REGION_ID, mnt_dat, pos);
if (ret != mnt_dat_sz) if (ret != pos)
{ {
state->err = -1; state->err = -1;
fprintf(stderr, "Error: failed to write darshan log mount data.\n"); fprintf(stderr, "Error: failed to write darshan log mount data.\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment