]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: fix 'p'rint error on empty PT
authorKarel Zak <kzak@redhat.com>
Mon, 27 Jan 2014 16:31:24 +0000 (17:31 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 11 Mar 2014 10:35:13 +0000 (11:35 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisk.c
libfdisk/src/table.c

index 19658be9a218a2b5f76e76443f481f812e2e7dd1..fa74ec0ae776f1696d003eafb722d6d1d0ef7e01 100644 (file)
@@ -245,7 +245,8 @@ void list_disklabel(struct fdisk_context *cxt)
                return;
        if (fdisk_table_to_string(tb, cxt, NULL, 0, &str) == 0) {
                fputc('\n', stdout);
-               fputs(str, stdout);
+               if (str && *str)
+                       fputs(str, stdout);
        }
        fdisk_unref_table(tb);
 }
index 5d3a02c679ab7cbcb8bd4ad78fba97c41052a462..abf7f28b98aaf9c5ff940a1a3c22c3ca093a033a 100644 (file)
@@ -317,7 +317,7 @@ int fdisk_get_table(struct fdisk_context *cxt, struct fdisk_table **tb)
  * @cxt: fdisk context
  * @cols: array with wanted FDISK_COL_* columns
  * @ncols: number of items in the cols array
- * @data: returns table as a newlly allocated string
+ * @data: returns table as a newlly allocated string or NULL for empty PT
  *
  * If no @cols are specified then the default is printed (see
  * fdisk_get_columns() for the default columns).
@@ -341,6 +341,10 @@ int fdisk_table_to_string(struct fdisk_table *tb,
                return -EINVAL;
 
        DBG(TAB, dbgprint("generate string"));
+       *data = NULL;
+
+       if (!fdisk_table_get_nents(tb))
+               return 0;
 
        if (!cols || !ncols) {
                rc = fdisk_get_columns(cxt, 0, &cols, &ncols);
@@ -387,7 +391,6 @@ int fdisk_table_to_string(struct fdisk_table *tb,
        }
 
        rc = 0;
-       *data = NULL;
        if (!tt_is_empty(tt))
                rc = tt_print_table_to_string(tt, data);
        else