From: Karel Zak Date: Tue, 30 Apr 2024 08:26:09 +0000 (+0200) Subject: libsmartcols: fix column reduction X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=8aa25617467a1249669cff7240ca31973bf9a127;p=thirdparty%2Futil-linux.git 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 (cherry picked from commit 28c7c29b2d57705fdc4ff486b38937c73b2d9b5d) --- diff --git a/libsmartcols/src/calculate.c b/libsmartcols/src/calculate.c index 1426d235a..119651709 100644 --- a/libsmartcols/src/calculate.c +++ b/libsmartcols/src/calculate.c @@ -377,9 +377,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 */