From 2e35d2a73c8b44b5f719c9fd62b892f09297e53c Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Mon, 7 Jan 2008 19:12:58 +0000 Subject: Avoid valgrind errors with getline. --- src/librc/librc-misc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/librc') diff --git a/src/librc/librc-misc.c b/src/librc/librc-misc.c index f77b2f78..4a16e9fe 100644 --- a/src/librc/librc-misc.c +++ b/src/librc/librc-misc.c @@ -119,12 +119,13 @@ char *rc_getline (FILE *fp) len += BUFSIZ; line = xrealloc (line, sizeof (char) * len); p = line + last; + memset (p, 0, BUFSIZ); fgets (p, BUFSIZ, fp); last += strlen (p); } while (! feof (fp) && line[last - 1] != '\n'); /* Trim the trailing newline */ - if (line[--last] == '\n') + if (*line && line[--last] == '\n') line[last] = '\0'; return (line); -- cgit v1.2.3