From 4f02a0040705046b4fb890b2adad20c977df7876 Mon Sep 17 00:00:00 2001 From: ru Date: Mon, 10 Sep 2001 11:43:40 +0000 Subject: Fixed the -z option handling: -Wuninitialized if used without -t. PR: bin/30467 Null pointer dereference if used with -t. Maximum column width computation was wrong. --- usr.bin/rs/rs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'usr.bin/rs/rs.c') diff --git a/usr.bin/rs/rs.c b/usr.bin/rs/rs.c index bd7dc33..ebb4238 100644 --- a/usr.bin/rs/rs.c +++ b/usr.bin/rs/rs.c @@ -244,7 +244,7 @@ prepfile() register int j; char **lp; int colw; - int max = 0; + int max; int n; if (!nelem) @@ -281,15 +281,18 @@ prepfile() if (!(colwidths = (short *) malloc(ocols * sizeof(short)))) errx(1, "malloc"); if (flags & SQUEEZE) { + ep = elem; if (flags & TRANSPOSE) - for (ep = elem, i = 0; i < ocols; i++) { - for (j = 0; j < orows; j++) + for (i = 0; i < ocols; i++) { + max = 0; + for (j = 0; *ep != NULL && j < orows; j++) if ((n = strlen(*ep++)) > max) max = n; colwidths[i] = max + gutter; } else for (i = 0; i < ocols; i++) { + max = 0; for (j = i; j < nelem; j += ocols) if ((n = strlen(ep[j])) > max) max = n; -- cgit v1.1