]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Avoid valgrind errors with getline.
authorRoy Marples <roy@marples.name>
Mon, 7 Jan 2008 19:13:54 +0000 (19:13 +0000)
committerRoy Marples <roy@marples.name>
Mon, 7 Jan 2008 19:13:54 +0000 (19:13 +0000)
common.c

index 2330889fd7cc90fb2bf1c3d4dc77408ad582f230..84f050800d5a5e1430a9924f78edcfd53174f7e9 100644 (file)
--- a/common.c
+++ b/common.c
@@ -57,12 +57,13 @@ char *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);