]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: avoid division by zero [clang scan]
authorKarel Zak <kzak@redhat.com>
Wed, 15 May 2019 15:10:38 +0000 (17:10 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 15 May 2019 15:10:38 +0000 (17:10 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/gpt.c

index b12a9cb60a806c455ad2978d4b2f23306ecb968c..1658782a857b42dc2a24f5ceb79047e086848281 100644 (file)
@@ -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;
        }