Skip to content

Commit 143e090

Browse files
committed
working on valgrind safe-ness
1 parent d242755 commit 143e090

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

c/xdifile.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ XDI_readfile(char *filename, XDIFile *xdifile) {
9797
char *col_labels[MAX_COLUMNS], *col_units[MAX_COLUMNS];
9898
char *c, *line, *fullline, *mkey, *mval, *version_xdi, *version_extra;
9999
char *reword;
100-
char tlabel[32];
101-
char comments[1024] = "";
100+
char tlabel[32] = {'\0'};
101+
char comments[1025] = {'\0'};
102+
char elem[3] = {'\0'};
102103
double dval ;
103104
double *outer_arr, outer_arr0;
104105
long *outer_pts;
@@ -115,12 +116,20 @@ XDI_readfile(char *filename, XDIFile *xdifile) {
115116

116117
iret = 0;
117118

119+
strcpy(comments, " ");
120+
xdifile->comments = calloc(1025, sizeof(char));
121+
strcpy(xdifile->comments, comments);
122+
123+
strcpy(elem, " ");
124+
xdifile->element = calloc(3, sizeof(char));
125+
strncpy(xdifile->element, elem, 2);
126+
118127
COPY_STRING(xdifile->xdi_libversion, XDI_VERSION);
119128
COPY_STRING(xdifile->xdi_version, "");
120129
COPY_STRING(xdifile->extra_version, "");
121-
COPY_STRING(xdifile->element, "__");
130+
/* COPY_STRING(xdifile->element, "__"); */
122131
COPY_STRING(xdifile->edge, "_");
123-
COPY_STRING(xdifile->comments, "");
132+
/* COPY_STRING(xdifile->comments, comments); */
124133
COPY_STRING(xdifile->error_line, "");
125134
COPY_STRING(xdifile->outer_label, "");
126135
xdifile->nouter = 1;
@@ -244,7 +253,8 @@ XDI_readfile(char *filename, XDIFile *xdifile) {
244253
} else if (strcasecmp(mkey, TOK_ELEM) == 0) {
245254
for (j = 0; j < n_elems; j++) {
246255
if (strcasecmp(ValidElems[j], mval) == 0) {
247-
COPY_STRING(xdifile->element, mval);
256+
/* COPY_STRING(xdifile->element, mval); */
257+
strncpy(xdifile->element, mval, 2);
248258
break;
249259
}
250260
}
@@ -318,7 +328,7 @@ XDI_readfile(char *filename, XDIFile *xdifile) {
318328
COPY_STRING(line, textlines[i]);
319329
ncols = make_words(line, words, MAX_WORDS);
320330

321-
COPY_STRING(xdifile->comments, comments);
331+
strcpy(xdifile->comments, comments);
322332
COPY_STRING(xdifile->filename, filename);
323333

324334
maxcol++;

0 commit comments

Comments
 (0)