Index: ul.c =================================================================== --- ul.c (revision 301965) +++ ul.c (working copy) @@ -78,7 +78,9 @@ int c_width; /* width or -1 if multi-column char. filler */ } ; -static struct CHAR obuf[MAXBUF]; +static struct CHAR sobuf[MAXBUF]; // static output buffer +static struct CHAR *obuf = sobuf; +static int buflen = MAXBUF; static int col, maxcol; static int mode; static int halfpos; @@ -151,6 +153,9 @@ else filter(f); } + if (obuf != sobuf) { + free(obuf); + } exit(0); } @@ -166,9 +171,26 @@ { wint_t c; int i, w; + int copy = 0; - while ((c = getwc(f)) != WEOF && col < MAXBUF) switch(c) { - + while ((c = getwc(f)) != WEOF) { + if (col == buflen) { + if (obuf == sobuf) { + obuf = NULL; + copy = 1; + } + obuf = realloc(obuf, sizeof(*obuf) * 2 * buflen); + if (obuf == NULL) { + obuf = sobuf; + break; + } else if (copy) { + memcpy(obuf, sobuf, sizeof(*obuf) * buflen); + copy = 0; + } + bzero((char *)(obuf + buflen), sizeof(*obuf) * buflen); + buflen *= 2; + } + switch(c) { case '\b': if (col > 0) col--; @@ -289,6 +311,7 @@ maxcol = col; continue; } + } if (ferror(f)) err(1, NULL); if (maxcol) @@ -405,7 +428,7 @@ initbuf(void) { - bzero((char *)obuf, sizeof (obuf)); /* depends on NORMAL == 0 */ + bzero((char *)obuf, buflen * sizeof(*obuf)); /* depends on NORMAL == 0 */ col = 0; maxcol = 0; mode &= ALTSET;