]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: init symbols when necessary
authorKarel Zak <kzak@redhat.com>
Wed, 2 Apr 2014 12:05:10 +0000 (14:05 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 3 Apr 2014 10:29:20 +0000 (12:29 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/src/table.c
libsmartcols/src/table_print.c

index 94df47b0573a8a7a184d80b914f7b7d046bfb1c9..dd26410fe7b55033f595bc3b7c545edb9948dc25 100644 (file)
@@ -60,9 +60,11 @@ struct libscols_table *scols_new_table(struct libscols_symbols *syms)
        INIT_LIST_HEAD(&tb->tb_lines);
        INIT_LIST_HEAD(&tb->tb_columns);
 
-       if (scols_table_set_symbols(tb, syms) == 0)
-               return tb;
+       if (syms && scols_table_set_symbols(tb, syms) != 0)
+               goto err;
 
+       return tb;
+err:
        scols_unref_table(tb);
        return NULL;
 }
index 306f2d2e79e05819cfa05dad9bf7b84f6a435922..f3cdf70c7c370b20704162ba9c9f72e02546fa93 100644 (file)
@@ -553,6 +553,9 @@ int scols_print_table(struct libscols_table *tb)
        if (!tb)
                return -1;
 
+       if (!tb->symbols)
+               scols_table_set_symbols(tb, NULL);      /* use default */
+
        tb->is_term = isatty(STDOUT_FILENO);
        tb->termwidth = tb->is_term ? get_terminal_width() : 0;
        if (tb->termwidth <= 0)