Avoid valgrind errors with getline.
This commit is contained in:
parent
81b8e5450e
commit
2e35d2a73c
@ -119,12 +119,13 @@ char *rc_getline (FILE *fp)
|
|||||||
len += BUFSIZ;
|
len += BUFSIZ;
|
||||||
line = xrealloc (line, sizeof (char) * len);
|
line = xrealloc (line, sizeof (char) * len);
|
||||||
p = line + last;
|
p = line + last;
|
||||||
|
memset (p, 0, BUFSIZ);
|
||||||
fgets (p, BUFSIZ, fp);
|
fgets (p, BUFSIZ, fp);
|
||||||
last += strlen (p);
|
last += strlen (p);
|
||||||
} while (! feof (fp) && line[last - 1] != '\n');
|
} while (! feof (fp) && line[last - 1] != '\n');
|
||||||
|
|
||||||
/* Trim the trailing newline */
|
/* Trim the trailing newline */
|
||||||
if (line[--last] == '\n')
|
if (*line && line[--last] == '\n')
|
||||||
line[last] = '\0';
|
line[last] = '\0';
|
||||||
|
|
||||||
return (line);
|
return (line);
|
||||||
|
Loading…
Reference in New Issue
Block a user