summaryrefslogtreecommitdiffstats
path: root/common.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-05-19 13:16:03 +0000
committerRoy Marples <roy@marples.name>2008-05-19 13:16:03 +0000
commit0788461c46ba10ecc784734630695a4764b5c87c (patch)
treec17191f5a277e84a3c87fdd68ca8429cd6b48d29 /common.c
parent37305c908cac2f8489ed6fa0cff401804452485f (diff)
downloaddhcpcd-0788461c46ba10ecc784734630695a4764b5c87c.tar.xz
Fix a potential segfault.
Diffstat (limited to 'common.c')
-rw-r--r--common.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/common.c b/common.c
index 184caa29..513e1251 100644
--- a/common.c
+++ b/common.c
@@ -55,24 +55,20 @@ get_line(char **line, size_t *len, FILE *fp)
char *p;
size_t last = 0;
- if (feof(fp))
- return 0;
-
- do {
+ while(!feof(fp)) {
if (*line == NULL || last != 0) {
*len += BUFSIZ;
- *line = xrealloc(*line, *len);
+ *line = realloc(*line, *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 && (*line)[last - 1] == '\n')
- (*line)[last - 1] = '\0';
-
+ if (last && (*line)[last - 1] == '\n') {
+ (*line)[last - 1] = '\0';
+ break;
+ }
+ }
return last;
}