]> 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>
Tue, 30 Apr 2024 08:29:45 +0000 (10:29 +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>
libsmartcols/src/calculate.c

index deabb0794c5a38e21a5fa5aba21f5d4ab013fdf1..86e1b27992f6185cf6650b70e527b212d761ae10 100644 (file)
@@ -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 */