From c8deb2dc55d714942328f31a23ce56a2649e3c64 Mon Sep 17 00:00:00 2001 From: joerg Date: Tue, 30 Sep 1997 19:42:05 +0000 Subject: Fix a number of fixed-size buffers etc. PR: bin/4520 Submitted by: gjm11@dpmms.cam.ac.uk (Gareth McCaughan) --- usr.bin/fmt/fmt.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'usr.bin/fmt/fmt.c') diff --git a/usr.bin/fmt/fmt.c b/usr.bin/fmt/fmt.c index fc27f65..51cbe5c 100644 --- a/usr.bin/fmt/fmt.c +++ b/usr.bin/fmt/fmt.c @@ -42,7 +42,7 @@ static char copyright[] = static char sccsid[] = "@(#)fmt.c 8.1 (Berkeley) 7/20/93"; #else static const char rcsid[] = - "$Id: fmt.c,v 1.9 1997/07/03 07:19:46 charnier Exp $"; + "$Id: fmt.c,v 1.10 1997/08/21 03:41:41 jlemon Exp $"; #endif #endif /* not lint */ @@ -339,9 +339,22 @@ split(line) char line[]; { register char *cp, *cp2; - char word[BUFSIZ]; + static char *word=0; + static int wordsize=0; int wordl; /* LIZ@UOM 6/18/85 */ + { + int l = strlen(line); + if (l >= wordsize) { + if (word) + free(word); + wordsize = (l+66)&~63; + word = malloc(wordsize); + if (word == NULL) + abort(); + } + } + cp = line; while (*cp) { cp2 = word; @@ -364,7 +377,7 @@ split(line) */ if (*cp == '\0') { *cp2++ = ' '; - if (index(".:!", cp[-1])) + if (cp != line && index(".:!", cp[-1])) *cp2++ = ' '; } while (*cp == ' ') @@ -386,8 +399,9 @@ split(line) * there ain't nothing in there yet. At the bottom of this whole mess, * leading tabs are reinserted. */ -char outbuf[BUFSIZ]; /* Sandbagged output line image */ +char *outbuf; /* Sandbagged output line image */ char *outp; /* Pointer in above */ +int outbuf_size; /* er, size of outbuf */ /* * Initialize the output section. @@ -395,6 +409,10 @@ char *outp; /* Pointer in above */ void setout() { + outbuf = malloc(BUFSIZ); + if (outbuf == 0) + abort(); + outbuf_size = BUFSIZ; outp = NOSTR; } @@ -426,6 +444,15 @@ pack(word,wl) register char *cp; register int s, t; + if (((outp==NOSTR) ? wl : outp-outbuf + wl) >= outbuf_size) { + char *old_outbuf = outbuf; + outbuf_size *= 2; + outbuf = realloc(outbuf, outbuf_size); + if (outbuf == 0) + abort(); + outp += outbuf-old_outbuf; + } + if (outp == NOSTR) leadin(); /* -- cgit v1.1