From fc732ffe205b975367149e80a047f95edf555188 Mon Sep 17 00:00:00 2001 From: dwmalone Date: Tue, 3 Apr 2001 18:03:29 +0000 Subject: [PATCH] Round up before checking if the width is smaller than the widest column, otherwise we may divide by zero later. PR: 26283 Reviewed by: roam --- usr.bin/column/column.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/usr.bin/column/column.c b/usr.bin/column/column.c index 043ab9df248..e0a50fce11b 100644 --- a/usr.bin/column/column.c +++ b/usr.bin/column/column.c @@ -29,6 +29,8 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $FreeBSD$ */ #ifndef lint @@ -52,6 +54,8 @@ static const char sccsid[] = "@(#)column.c 8.4 (Berkeley) 5/4/95"; #include #include +#define TAB 8 + void c_columnate __P((void)); void *emalloc __P((int)); void input __P((FILE *)); @@ -120,6 +124,7 @@ main(argc, argv) if (!entries) exit(eval); + maxlength = (maxlength + TAB) & ~(TAB - 1); if (tflag) maketbl(); else if (maxlength >= termwidth) @@ -131,14 +136,12 @@ main(argc, argv) exit(eval); } -#define TAB 8 void c_columnate() { int chcnt, col, cnt, endcol, numcols; char **lp; - maxlength = (maxlength + TAB) & ~(TAB - 1); numcols = termwidth / maxlength; endcol = maxlength; for (chcnt = col = 0, lp = list;; ++lp) { @@ -166,7 +169,6 @@ r_columnate() { int base, chcnt, cnt, col, endcol, numcols, numrows, row; - maxlength = (maxlength + TAB) & ~(TAB - 1); numcols = termwidth / maxlength; numrows = entries / numcols; if (entries % numcols) -- 2.45.0