diff options
author | Karel Zak | 2019-05-15 17:10:38 +0200 |
---|---|---|
committer | Karel Zak | 2019-05-15 17:10:38 +0200 |
commit | 845fd622ed0f7bff383700cf777cee7fef486de5 (patch) | |
tree | f06b0a287357c91e2322b7294a72a4660ae63a50 /libfdisk | |
parent | libfdisk: remove unused code [clang scan] (diff) | |
download | kernel-qcow2-util-linux-845fd622ed0f7bff383700cf777cee7fef486de5.tar.gz kernel-qcow2-util-linux-845fd622ed0f7bff383700cf777cee7fef486de5.tar.xz kernel-qcow2-util-linux-845fd622ed0f7bff383700cf777cee7fef486de5.zip |
libfdisk: avoid division by zero [clang scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk')
-rw-r--r-- | libfdisk/src/gpt.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c index b12a9cb60..1658782a8 100644 --- a/libfdisk/src/gpt.c +++ b/libfdisk/src/gpt.c @@ -2748,8 +2748,13 @@ int fdisk_gpt_set_npartitions(struct fdisk_context *cxt, uint32_t entries) /* calculate the size (bytes) of the entries array */ rc = gpt_calculate_sizeof_ents(gpt->pheader, entries, &new_size); if (rc) { - fdisk_warnx(cxt, _("The number of the partition has to be smaller than %zu."), - UINT32_MAX / le32_to_cpu(gpt->pheader->sizeof_partition_entry)); + uint32_t entry_size = le32_to_cpu(gpt->pheader->sizeof_partition_entry); + + if (entry_size == 0) + fdisk_warnx(cxt, _("The partition entry size is zero.")); + else + fdisk_warnx(cxt, _("The number of the partition has to be smaller than %zu."), + UINT32_MAX / entry_size); return rc; } |