diff options
author | Karel Zak <kzak@redhat.com> | 2024-04-30 10:26:09 +0200 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2024-04-30 10:29:45 +0200 |
commit | 28c7c29b2d57705fdc4ff486b38937c73b2d9b5d (patch) | |
tree | 1bd20e9489ed4909335fc470980d0e8b07792c2a | |
parent | 926b6077333554924756ba648c9df38c803c48bc (diff) | |
download | util-linux-28c7c29b2d57705fdc4ff486b38937c73b2d9b5d.tar.gz |
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 <kzak@redhat.com>
-rw-r--r-- | libsmartcols/src/calculate.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/libsmartcols/src/calculate.c b/libsmartcols/src/calculate.c index deabb0794c..86e1b27992 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 */ |