summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2014-01-27 17:31:24 +0100
committerKarel Zak2014-03-11 11:35:13 +0100
commit849968b9ba621a3c2e8913256bcad00d5a830a91 (patch)
tree0d9a7d77dd81c388334516c886f864844a55dcf0
parentcfdisk: improve info line and menu updates (diff)
downloadkernel-qcow2-util-linux-849968b9ba621a3c2e8913256bcad00d5a830a91.tar.gz
kernel-qcow2-util-linux-849968b9ba621a3c2e8913256bcad00d5a830a91.tar.xz
kernel-qcow2-util-linux-849968b9ba621a3c2e8913256bcad00d5a830a91.zip
fdisk: fix 'p'rint error on empty PT
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--fdisks/fdisk.c3
-rw-r--r--libfdisk/src/table.c7
2 files changed, 7 insertions, 3 deletions
diff --git a/fdisks/fdisk.c b/fdisks/fdisk.c
index 19658be9a..fa74ec0ae 100644
--- a/fdisks/fdisk.c
+++ b/fdisks/fdisk.c
@@ -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);
}
diff --git a/libfdisk/src/table.c b/libfdisk/src/table.c
index 5d3a02c67..abf7f28b9 100644
--- a/libfdisk/src/table.c
+++ b/libfdisk/src/table.c
@@ -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