summaryrefslogtreecommitdiffstats
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
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@
-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 681062e8..d676f4ce 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)
if (*buf == NULL || *bufsiz == 0) {
- *bufsiz = BUFSIZ;
- if ((*buf = malloc(*bufsiz)) == NULL)
+ if ((*buf = malloc(BUFSIZ)) == NULL)
return -1;
+ *bufsiz = BUFSIZ;
}
for (ptr = *buf, eptr = *buf + *bufsiz;;) {