summaryrefslogtreecommitdiff
path: root/openbsd-compat/bsd-getline.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@dtucker.net>2018-07-06 13:32:02 +1000
committerDarren Tucker <dtucker@dtucker.net>2018-07-06 13:32:02 +1000
commit872517ddbb72deaff31d4760f28f2b0a1c16358f (patch)
tree1939ac91eba31eca9a690342223fa9930b7795b8 /openbsd-compat/bsd-getline.c
parent3deb56f7190a414dc264e21e087a934fa1847283 (diff)
Defer setting bufsiz in getdelim.
Do not write to bufsiz until we are sure the malloc has succeeded, in case any callers rely on it (which they shouldn't). ok djm@
Diffstat (limited to 'openbsd-compat/bsd-getline.c')
-rw-r--r--openbsd-compat/bsd-getline.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/openbsd-compat/bsd-getline.c b/openbsd-compat/bsd-getline.c
index 681062e80..d676f4cef 100644
--- a/openbsd-compat/bsd-getline.c
+++ b/openbsd-compat/bsd-getline.c
@@ -53,9 +53,9 @@ getdelim(char **buf, size_t *bufsiz, int delimiter, FILE *fp)
53 53
54 54
55 if (*buf == NULL || *bufsiz == 0) { 55 if (*buf == NULL || *bufsiz == 0) {
56 *bufsiz = BUFSIZ; 56 if ((*buf = malloc(BUFSIZ)) == NULL)
57 if ((*buf = malloc(*bufsiz)) == NULL)
58 return -1; 57 return -1;
58 *bufsiz = BUFSIZ;
59 } 59 }
60 60
61 for (ptr = *buf, eptr = *buf + *bufsiz;;) { 61 for (ptr = *buf, eptr = *buf + *bufsiz;;) {