]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: fix column reduction
authorKarel Zak <kzak@redhat.com>
Tue, 30 Apr 2024 08:26:09 +0000 (10:26 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 27 May 2024 13:12:06 +0000 (15:12 +0200)
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>
(cherry picked from commit 28c7c29b2d57705fdc4ff486b38937c73b2d9b5d)

libsmartcols/src/calculate.c

index 1426d235a167358c3a3af6b5ffc15f91cae1a3a3..1196517097c8772aea71b7b11fd9e4f540f53748 100644 (file)
@@ -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 */