]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: clean up scols usage
authorKarel Zak <kzak@redhat.com>
Thu, 3 Apr 2014 08:48:09 +0000 (10:48 +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>
sys-utils/lscpu.c

index 8a5a9c693ad643e5875defb790290e3f43bfaf4c..564a705b033a621352cf3f076cd5ad939b901dad 100644 (file)
@@ -1226,7 +1226,8 @@ print_readable(struct lscpu_desc *desc, int cols[], int ncols,
               struct lscpu_modifier *mod)
 {
        int i;
-       char buf[BUFSIZ], *data;
+       char buf[BUFSIZ];
+       const char *data;
        struct libscols_table *table = scols_new_table(NULL);
 
        if (!table)
@@ -1235,7 +1236,7 @@ print_readable(struct lscpu_desc *desc, int cols[], int ncols,
        for (i = 0; i < ncols; i++) {
                data = get_cell_header(desc, cols[i], mod, buf, sizeof(buf));
                if (!scols_table_new_column(table, xstrdup(data), 0, 0))
-                       return;
+                       err(EXIT_FAILURE, _("failed to initialize output column"));
        }
 
        for (i = 0; i < desc->ncpuspos; i++) {
@@ -1251,17 +1252,15 @@ print_readable(struct lscpu_desc *desc, int cols[], int ncols,
                        continue;
 
                line = scols_table_new_line(table, NULL);
-               if (!line) {
-                       scols_unref_table(table);
-                       return;
-               }
-
+               if (!line)
+                       err(EXIT_FAILURE, _("failed to initialize output line"));
 
                for (c = 0; c < ncols; c++) {
                        data = get_cell_data(desc, i, cols[c], mod,
                                             buf, sizeof(buf));
-                       scols_line_set_data(line, c,
-                                       xstrdup(data && *data ? data : "-"));
+                       if (!data || !*data)
+                               data = "-";
+                       scols_line_set_data(line, c, data);
                }
        }