]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: don't print empty column
authorKarel Zak <kzak@redhat.com>
Mon, 4 Jun 2018 13:20:28 +0000 (15:20 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 11 Jul 2018 14:08:04 +0000 (16:08 +0200)
The commit 0f9f927b6f62cb7f488fadfad76c4a5defdefe36 forces
libsmartcols to use one byte as a minimal column width. This seems
like a bug if the column is empty and without header.

$ printf ':a:b\n' | column -t -s ':' -o ':'
 :a:b

Fixed version:
$ printf ':a:b\n' | column -t -s ':' -o ':'
:a:b

Reported-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/src/table_print.c

index 67e51076eac316c6cc484472a820fbf98c1d829b..8ecfc30e2d8526c6b8fd295f3a3bc9a3c45de8b8 100644 (file)
@@ -1051,7 +1051,7 @@ static int count_column_width(struct libscols_table *tb,
 {
        struct libscols_line *ln;
        struct libscols_iter itr;
-       int count = 0, rc = 0;
+       int count = 0, rc = 0, no_header = 0;
        size_t sum = 0;
 
        assert(tb);
@@ -1067,7 +1067,9 @@ static int count_column_width(struct libscols_table *tb,
                if (scols_cell_get_data(&cl->header)) {
                        size_t len = mbs_safe_width(scols_cell_get_data(&cl->header));
                        cl->width_min = max(cl->width_min, len);
-               }
+               } else
+                       no_header = 1;
+
                if (!cl->width_min)
                        cl->width_min = 1;
        }
@@ -1123,6 +1125,11 @@ static int count_column_width(struct libscols_table *tb,
 
                cl->width = (size_t) cl->width_hint;
 
+
+       /* Column without header and data, set minimal size to zero (default is 1) */
+       if (cl->width_max == 0 && no_header && cl->width_min == 1 && cl->width <= 1)
+               cl->width = cl->width_min = 0;
+
 done:
        ON_DBG(COL, dbg_column(tb, cl));
        return rc;