From 28c7c29b2d57705fdc4ff486b38937c73b2d9b5d Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 30 Apr 2024 10:26:09 +0200 Subject: [PATCH] libsmartcols: fix column reduction 4013986: libsmartcols: TAB: [0x5626b97f8e10]: #5 reduce stage (width=38, term=1) 4013986: libsmartcols: COL: [0x5626b97f9130]: [01] (null) reduced 2-->18446744073709551615 Fixes: https://github.com/util-linux/util-linux/issues/3003 Signed-off-by: Karel Zak Reference:https://github.com/util-linux/util-linux/commit/28c7c29b2d57705fdc4ff486b38937c73b2d9b5d Conflict:NA --- libsmartcols/src/calculate.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libsmartcols/src/calculate.c b/libsmartcols/src/calculate.c index deabb079..86e1b279 100644 --- a/libsmartcols/src/calculate.c +++ b/libsmartcols/src/calculate.c @@ -379,9 +379,14 @@ static int reduce_column(struct libscols_table *tb, /* columns are reduced in "bad first" way, be more * agresive for the the worst column */ reduce = 3; - if (cl->width - reduce < st->width_min) - reduce = cl->width - st->width_min; - cl->width -= reduce; + + if (cl->width < reduce) + reduce = cl->width; + + if (cl->width - reduce > st->width_min) + cl->width -= reduce; + else + cl->width = st->width_min; break; default: return -1; /* no more stages */ -- 2.33.0