diff options
| author | cjep <cjep@NetBSD.org> | 2021-05-25 11:25:59 +0000 |
|---|---|---|
| committer | cjep <cjep@NetBSD.org> | 2021-05-25 11:25:59 +0000 |
| commit | 5631a155a150d33c4d55ca83cfe363a2061afddf (patch) | |
| tree | 71acaf0f125a455c7c234b118ece70b4f4fff04a /usr.bin/patch/patch.c | |
| parent | 8f8dd947f97ced18de74a829ac46e1ce569d61b8 (diff) | |
As per OpenBSD, use malloc for the line buffer. Fixes the known issue
with long lines and makes our ATF test suite pass fully.
Closes PR bin/54620 from coypu who suggested the approach.
Reviewed by christos.
Diffstat (limited to 'usr.bin/patch/patch.c')
| -rw-r--r-- | usr.bin/patch/patch.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c index 33c170e145e..df62ca868b2 100644 --- a/usr.bin/patch/patch.c +++ b/usr.bin/patch/patch.c @@ -1,7 +1,7 @@ /* * $OpenBSD: patch.c,v 1.45 2007/04/18 21:52:24 sobrado Exp $ * $DragonFly: src/usr.bin/patch/patch.c,v 1.10 2008/08/10 23:39:56 joerg Exp $ - * $NetBSD: patch.c,v 1.31 2021/02/20 09:17:13 nia Exp $ + * $NetBSD: patch.c,v 1.32 2021/05/25 11:25:59 cjep Exp $ */ /* @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: patch.c,v 1.31 2021/02/20 09:17:13 nia Exp $"); +__RCSID("$NetBSD: patch.c,v 1.32 2021/05/25 11:25:59 cjep Exp $"); #include <sys/types.h> #include <sys/stat.h> @@ -53,8 +53,8 @@ __RCSID("$NetBSD: patch.c,v 1.31 2021/02/20 09:17:13 nia Exp $"); mode_t filemode = 0644; -char buf[MAXLINELEN]; /* general purpose buffer */ -size_t buf_len = sizeof(buf); +char *buf; /* general purpose buffer */ +size_t bufsz; /* general purpose buffer size */ bool using_plan_a = true; /* try to keep everything in memory */ bool out_of_mem = false; /* ran out of memory in plan a */ @@ -157,6 +157,11 @@ main(int argc, char *argv[]) const char *tmpdir; char *v; + bufsz = INITLINELEN; + if ((buf = malloc(bufsz)) == NULL) + pfatal("allocating input buffer"); + buf[0] = '\0'; + setbuf(stderr, serrbuf); for (i = 0; i < MAXFILEC; i++) filearg[i] = NULL; |
