]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: add and fix __format__ attributes
authorKarel Zak <kzak@redhat.com>
Fri, 18 Jun 2021 14:41:20 +0000 (16:41 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 18 Jun 2021 14:42:57 +0000 (16:42 +0200)
Reported-by: Jan Pazdziora <jpazdziora@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/cfdisk.c
disk-utils/fdisk-list.c
disk-utils/sfdisk.c
libfdisk/src/dos.c
libfdisk/src/gpt.c
libfdisk/src/libfdisk.h.in
libfdisk/src/sgi.c
libfdisk/src/sun.c

index 747953b22a95c04b8b2e7391c09d8f694674801a..b8891316eb541e6270490dbec7b214f5e63ea15e 100644 (file)
@@ -141,9 +141,14 @@ static void menu_refresh_size(struct cfdisk *cf);
 
 static int ui_end(void);
 static int ui_refresh(struct cfdisk *cf);
-static void ui_warnx(const char *fmt, ...);
-static void ui_warn(const char *fmt, ...);
-static void ui_info(const char *fmt, ...);
+
+static void ui_warnx(const char *fmt, ...)
+                       __attribute__((__format__ (__printf__, 1, 2)));
+static void ui_warn(const char *fmt, ...)
+                       __attribute__((__format__ (__printf__, 1, 2)));
+static void ui_info(const char *fmt, ...)
+                       __attribute__((__format__ (__printf__, 1, 2)));
+
 static void ui_draw_menu(struct cfdisk *cf);
 static int ui_menu_move(struct cfdisk *cf, int key);
 static void ui_menu_resize(struct cfdisk *cf);
@@ -630,13 +635,13 @@ static int ask_callback(struct fdisk_context *cxt __attribute__((__unused__)),
 
        switch(fdisk_ask_get_type(ask)) {
        case FDISK_ASKTYPE_INFO:
-               ui_info(fdisk_ask_print_get_mesg(ask));
+               ui_info("%s", fdisk_ask_print_get_mesg(ask));
                break;
        case FDISK_ASKTYPE_WARNX:
-               ui_warnx(fdisk_ask_print_get_mesg(ask));
+               ui_warnx("%s", fdisk_ask_print_get_mesg(ask));
                break;
        case FDISK_ASKTYPE_WARN:
-               ui_warn(fdisk_ask_print_get_mesg(ask));
+               ui_warn("%s", fdisk_ask_print_get_mesg(ask));
                break;
        case FDISK_ASKTYPE_MENU:
                ask_menu(ask, (struct cfdisk *) data);
@@ -668,7 +673,8 @@ static int ui_end(void)
        return 0;
 }
 
-static void ui_vprint_center(size_t line, int attrs, const char *fmt, va_list ap)
+static void __attribute__((__format__ (__printf__, 3, 0)))
+       ui_vprint_center(size_t line, int attrs, const char *fmt, va_list ap)
 {
        size_t width;
        char *buf = NULL;
@@ -698,7 +704,8 @@ static void ui_vprint_center(size_t line, int attrs, const char *fmt, va_list ap
        free(buf);
 }
 
-static void ui_center(size_t line, const char *fmt, ...)
+static void __attribute__((__format__ (__printf__, 2, 3)))
+       ui_center(size_t line, const char *fmt, ...)
 {
        va_list ap;
        va_start(ap, fmt);
@@ -706,7 +713,8 @@ static void ui_center(size_t line, const char *fmt, ...)
        va_end(ap);
 }
 
-static void ui_warnx(const char *fmt, ...)
+static void __attribute__((__format__ (__printf__, 1, 2)))
+       ui_warnx(const char *fmt, ...)
 {
        va_list ap;
        va_start(ap, fmt);
@@ -721,7 +729,8 @@ static void ui_warnx(const char *fmt, ...)
        va_end(ap);
 }
 
-static void ui_warn(const char *fmt, ...)
+static void __attribute__((__format__ (__printf__, 1, 2)))
+       ui_warn(const char *fmt, ...)
 {
        char *fmt_m;
        va_list ap;
@@ -747,8 +756,10 @@ static void ui_clean_warn(void)
        clrtoeol();
 }
 
-static int __attribute__((__noreturn__)) ui_err(int rc, const char *fmt, ...)
-               {
+static int __attribute__((__noreturn__))
+          __attribute__((__format__ (__printf__, 2, 3)))
+       ui_err(int rc, const char *fmt, ...)
+{
        va_list ap;
        ui_end();
 
@@ -761,7 +772,9 @@ static int __attribute__((__noreturn__)) ui_err(int rc, const char *fmt, ...)
        exit(rc);
 }
 
-static int __attribute__((__noreturn__)) ui_errx(int rc, const char *fmt, ...)
+static int __attribute__((__noreturn__))
+          __attribute__((__format__ (__printf__, 2, 3)))
+       ui_errx(int rc, const char *fmt, ...)
                {
        va_list ap;
        ui_end();
@@ -775,7 +788,8 @@ static int __attribute__((__noreturn__)) ui_errx(int rc, const char *fmt, ...)
        exit(rc);
 }
 
-static void ui_info(const char *fmt, ...)
+static void __attribute__((__format__ (__printf__, 1, 2)))
+       ui_info(const char *fmt, ...)
 {
        va_list ap;
        va_start(ap, fmt);
@@ -796,7 +810,8 @@ static void ui_clean_info(void)
        clrtoeol();
 }
 
-static void ui_hint(const char *fmt, ...)
+static void __attribute__((__format__ (__printf__, 1, 2)))
+       ui_hint(const char *fmt, ...)
 {
        va_list ap;
        va_start(ap, fmt);
@@ -1130,7 +1145,7 @@ static void ui_draw_menuitem(struct cfdisk *cf,
        if (cf->menu->idx == idx) {
                standend();
                if (d->desc)
-                       ui_hint(_(d->desc));
+                       ui_hint("%s", _(d->desc));
        }
 }
 
@@ -1778,7 +1793,7 @@ static ssize_t ui_get_string(const char *prompt,
        mbs_edit_goto(edit, MBS_EDIT_END);
 
        if (hint)
-               ui_hint(hint);
+               ui_hint("%s", hint);
        else
                ui_clean_hint();
 
index 62aa2b3f5c4988f4e70b72657baa4312380e1b7b..9f64decabad69f7946fc4d4a38386ca4dce4217b 100644 (file)
@@ -68,10 +68,10 @@ void list_disk_geometry(struct fdisk_context *cxt)
                fdisk_info(cxt, _("Disk model: %s"), fdisk_get_devmodel(cxt));
 
        if (lb && (fdisk_label_require_geometry(lb) || fdisk_use_cylinders(cxt)))
-               fdisk_info(cxt, _("Geometry: %d heads, %llu sectors/track, %llu cylinders"),
+               fdisk_info(cxt, _("Geometry: %d heads, %ju sectors/track, %ju cylinders"),
                               fdisk_get_geom_heads(cxt),
-                              fdisk_get_geom_sectors(cxt),
-                              fdisk_get_geom_cylinders(cxt));
+                              (uintmax_t) fdisk_get_geom_sectors(cxt),
+                              (uintmax_t) fdisk_get_geom_cylinders(cxt));
 
        fdisk_info(cxt, _("Units: %s of %d * %ld = %ld bytes"),
               fdisk_get_unit(cxt, FDISK_PLURAL),
@@ -182,7 +182,7 @@ void list_disklabel(struct fdisk_context *cxt)
 
        /* print */
        if (!scols_table_is_empty(out)) {
-               fdisk_info(cxt, "");    /* just line break */
+               fdisk_info(cxt, "%s", "");      /* just line break */
                scols_print_table(out);
        }
 
@@ -193,14 +193,14 @@ void list_disklabel(struct fdisk_context *cxt)
                        continue;
                if (!fdisk_lba_is_phy_aligned(cxt, fdisk_partition_get_start(pa))) {
                        if (!post)
-                               fdisk_info(cxt, ""); /* line break */
+                               fdisk_info(cxt, "%s", ""); /* line break */
                        fdisk_warnx(cxt, _("Partition %zu does not start on physical sector boundary."),
                                          fdisk_partition_get_partno(pa) + 1);
                        post++;
                }
                if (fdisk_partition_has_wipe(cxt, pa)) {
                        if (!post)
-                               fdisk_info(cxt, ""); /* line break */
+                               fdisk_info(cxt, "%s", ""); /* line break */
 
                        fdisk_info(cxt, _("Filesystem/RAID signature on partition %zu will be wiped."),
                                        fdisk_partition_get_partno(pa) + 1);
@@ -210,7 +210,7 @@ void list_disklabel(struct fdisk_context *cxt)
 
        if (fdisk_table_wrong_order(tb)) {
                if (!post)
-                       fdisk_info(cxt, ""); /* line break */
+                       fdisk_info(cxt, "%s", ""); /* line break */
                fdisk_info(cxt, _("Partition table entries are not in disk order."));
        }
 done:
@@ -308,7 +308,7 @@ void list_freespace(struct fdisk_context *cxt)
 
        /* print */
        if (!scols_table_is_empty(out)) {
-               fdisk_info(cxt, "");    /* line break */
+               fdisk_info(cxt, "%s", "");      /* line break */
                scols_print_table(out);
        }
 done:
index 3d390edf9383aeb5cde71ce3d71fdb39858aaca4..526d090071d5fb4a92c25a524ce2d1947fe8f8fa 100644 (file)
@@ -468,7 +468,7 @@ static int move_partition_data(struct sfdisk *sf, size_t partno, struct fdisk_pa
                typescript = mk_backup_filename_tpl(sf->move_typescript, devname, ".move");
 
        if (!sf->quiet) {
-               fdisk_info(sf->cxt,"");
+               fdisk_info(sf->cxt, "%s", "");
                color_scheme_enable("header", UL_COLOR_BOLD);
                fdisk_info(sf->cxt, sf->noact ? _("Data move: (--no-act)") : _("Data move:"));
                color_disable();
@@ -1926,7 +1926,7 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv)
                                rc = fdisk_add_partition(sf->cxt, pa, &cur_partno);
                                if (rc) {
                                        errno = -rc;
-                                       fdisk_warn(sf->cxt, _("Failed to add #%d partition"), next_partno + 1);
+                                       fdisk_warn(sf->cxt, _("Failed to add #%zu partition"), next_partno + 1);
                                }
                        }
 
index 4368e52666d911ec12a7108b789cb1c430856b74..eabedcc57241859325421436531803cfa8adc23d 100644 (file)
@@ -1257,7 +1257,8 @@ static int add_partition(struct fdisk_context *cxt, size_t n,
                if (start >= temp + fdisk_get_units_per_sector(cxt)
                    && read) {
                        if (!pa || !pa->start_follow_default)
-                               fdisk_info(cxt, _("Sector %llu is already allocated."), temp);
+                               fdisk_info(cxt, _("Sector %ju is already allocated."),
+                                               (uintmax_t) temp);
                        temp = start;
                        read = 0;
                        if (pa && fdisk_partition_has_start(pa))
@@ -1513,12 +1514,13 @@ static void check(struct fdisk_context *cxt, size_t n,
                                   "maximum %d"), n, h + 1, cxt->geom.heads);
        if (real_s >= cxt->geom.sectors)
                fdisk_warnx(cxt, _("Partition %zu: sector %d greater than "
-                                  "maximum %llu"), n, s, cxt->geom.sectors);
+                                  "maximum %ju"), n, s,
+                               (uintmax_t) cxt->geom.sectors);
        if (real_c >= cxt->geom.cylinders)
                fdisk_warnx(cxt, _("Partition %zu: cylinder %d greater than "
-                                  "maximum %llu"),
+                                  "maximum %ju"),
                                n, real_c + 1,
-                               cxt->geom.cylinders);
+                               (uintmax_t) cxt->geom.cylinders);
 
        if (cxt->geom.cylinders <= 1024 && start != total)
                fdisk_warnx(cxt, _("Partition %zu: previous sectors %u "
@@ -1704,11 +1706,11 @@ static int dos_verify_disklabel(struct fdisk_context *cxt)
        if (!nerrors) {
                fdisk_info(cxt, _("No errors detected."));
                if (total > n_sectors)
-                       fdisk_info(cxt, _("Total allocated sectors %llu greater "
-                               "than the maximum %llu."), total, n_sectors);
+                       fdisk_info(cxt, _("Total allocated sectors %ju greater "
+                               "than the maximum %ju."), (uintmax_t) total, (uintmax_t) n_sectors);
                else if (total < n_sectors)
-                       fdisk_info(cxt, _("Remaining %lld unallocated %ld-byte "
-                               "sectors."), n_sectors - total, cxt->sector_size);
+                       fdisk_info(cxt, _("Remaining %ju unallocated %ld-byte "
+                               "sectors."), (uintmax_t) n_sectors - total, cxt->sector_size);
        } else
                fdisk_warnx(cxt,
                        P_("%d error detected.", "%d errors detected.", nerrors),
@@ -1873,10 +1875,10 @@ static int dos_add_partition(struct fdisk_context *cxt,
                                        msg =  _("All space for primary partitions is in use.");
 
                                if (pa && fdisk_partition_has_start(pa)) {
-                                       fdisk_warnx(cxt, msg);
+                                       fdisk_warnx(cxt, "%s", msg);
                                        return -EINVAL;
                                }
-                               fdisk_info(cxt, msg);
+                               fdisk_info(cxt, "%s", msg);
                        }
                        DBG(LABEL, ul_debug("DOS: trying logical"));
                        rc = add_logical(cxt, pa, &res);
index 97b161312e59f0ee465840d89904278c71b33f09..5bda051de50b4b9bc8b8bcd16cb938d572182f02 100644 (file)
@@ -10,6 +10,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <inttypes.h>
+#include <stdint.h>
 #include <sys/stat.h>
 #include <sys/utsname.h>
 #include <sys/types.h>
@@ -50,7 +51,7 @@
 #define EFI_PMBR_OSTYPE     0xEE
 #define MSDOS_MBR_SIGNATURE 0xAA55
 #define GPT_PART_NAME_LEN   (72 / sizeof(uint16_t))
-#define GPT_NPARTITIONS     FDISK_GPT_NPARTITIONS_DEFAULT
+#define GPT_NPARTITIONS     ((size_t) FDISK_GPT_NPARTITIONS_DEFAULT)
 
 /* Globally unique identifier */
 struct gpt_guid {
@@ -951,7 +952,7 @@ static int valid_pmbr(struct fdisk_context *cxt)
 
                        fdisk_warnx(cxt, _("GPT PMBR size mismatch (%"PRIu64" != %"PRIu64") "
                                           "will be corrected by write."),
-                                       sz_lba, cxt->total_sectors - 1ULL);
+                                       sz_lba, cxt->total_sectors - (uint64_t) 1);
 
                        /* Note that gpt_write_pmbr() overwrites PMBR, but we want to keep it valid already
                         * in memory too to disable warnings when valid_pmbr() called next time */
@@ -2677,7 +2678,7 @@ static int gpt_create_disklabel(struct fdisk_context *cxt)
        fdisk_info(cxt, _("Created a new GPT disklabel (GUID: %s)."), str);
 
        if (gpt_get_nentries(gpt) < GPT_NPARTITIONS)
-               fdisk_info(cxt, _("The maximal number of partitions is %d (default is %d)."),
+               fdisk_info(cxt, _("The maximal number of partitions is %zu (default is %zu)."),
                                gpt_get_nentries(gpt), GPT_NPARTITIONS);
 done:
        return rc;
@@ -2758,7 +2759,7 @@ static int gpt_check_table_overlap(struct fdisk_context *cxt,
                }
                if (gpt_partition_end(e) > last_usable) {
                        fdisk_warnx(cxt, _("Partition #%zu out of range (maximal end is %"PRIu64" sectors)"),
-                                   i + 1, last_usable - 1ULL);
+                                   i + 1, last_usable - (uint64_t) 1);
                        rc = -EINVAL;
                }
        }
@@ -2806,7 +2807,7 @@ int fdisk_gpt_set_npartitions(struct fdisk_context *cxt, uint32_t nents)
                        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);
+                               (size_t) UINT32_MAX / entry_size);
                return rc;
        }
 
@@ -2858,7 +2859,7 @@ int fdisk_gpt_set_npartitions(struct fdisk_context *cxt, uint32_t nents)
        /* update library info */
        cxt->label->nparts_max = gpt_get_nentries(gpt);
 
-       fdisk_info(cxt, _("Partition table length changed from %"PRIu32" to %"PRIu64"."),
+       fdisk_info(cxt, _("Partition table length changed from %"PRIu32" to %"PRIu32"."),
                        old_nents, nents);
 
        fdisk_label_set_changed(cxt->label, 1);
index 6f2e77d047536bdceeeb70d53c4c690ad6a1e409..238aa1304b10d2f08025f55878c35a899f55046d 100644 (file)
@@ -875,9 +875,12 @@ size_t fdisk_ask_menu_get_nitems(struct fdisk_ask *ask);
 int fdisk_ask_print_get_errno(struct fdisk_ask *ask);
 const char *fdisk_ask_print_get_mesg(struct fdisk_ask *ask);
 
-int fdisk_info(struct fdisk_context *cxt, const char *fmt, ...);
-int fdisk_warn(struct fdisk_context *cxt, const char *fmt, ...);
-int fdisk_warnx(struct fdisk_context *cxt, const char *fmt, ...);
+int fdisk_info(struct fdisk_context *cxt, const char *fmt, ...)
+                       __attribute__ ((__format__ (__printf__, 2, 3)));
+int fdisk_warn(struct fdisk_context *cxt, const char *fmt, ...)
+                       __attribute__ ((__format__ (__printf__, 2, 3)));
+int fdisk_warnx(struct fdisk_context *cxt, const char *fmt, ...)
+                       __attribute__ ((__format__ (__printf__, 2, 3)));
 
 /* utils.h */
 extern char *fdisk_partname(const char *dev, size_t partno);
index 64adf345433c8990af139dc8f139dedef6f3bbc0..6740535046b808df87f4cd8ea27974323905e86b 100644 (file)
@@ -987,9 +987,10 @@ static int sgi_create_disklabel(struct fdisk_context *cxt)
                        /* otherwise print error and use truncated version */
                        fdisk_warnx(cxt,
                                _("BLKGETSIZE ioctl failed on %s. "
-                                 "Using geometry cylinder value of %llu. "
+                                 "Using geometry cylinder value of %ju. "
                                  "This value may be truncated for devices "
-                                 "> 33.8 GB."), cxt->dev_path, cxt->geom.cylinders);
+                                 "> 33.8 GB."), cxt->dev_path,
+                               (uintmax_t) cxt->geom.cylinders);
                }
        }
 
index 4c3b1d8cb62f1edcfe666fb80558feb8fb8c4195..dde9750a0e535b33b260f72b45ef3995d634af22 100644 (file)
@@ -83,10 +83,10 @@ static void set_partition(struct fdisk_context *cxt, size_t i,
                        fdisk_label_get_parttype_from_code(cxt->label, sysid);
 
        if (start / (cxt->geom.heads * cxt->geom.sectors) > UINT32_MAX)
-               fdisk_warnx(cxt, _("%#zu: start cylinder overflows Sun label limits"), i+1);
+               fdisk_warnx(cxt, _("#%zu: start cylinder overflows Sun label limits"), i+1);
 
        if (stop - start > UINT32_MAX)
-               fdisk_warnx(cxt, _("%#zu: number of sectors overflow Sun label limits"), i+1);
+               fdisk_warnx(cxt, _("#%zu: number of sectors overflow Sun label limits"), i+1);
 
        sunlabel->vtoc.infos[i].id = cpu_to_be16(sysid);
        sunlabel->vtoc.infos[i].flags = cpu_to_be16(0);
@@ -246,10 +246,10 @@ static int sun_create_disklabel(struct fdisk_context *cxt)
                } else {
                        fdisk_warnx(cxt,
                                _("BLKGETSIZE ioctl failed on %s. "
-                                 "Using geometry cylinder value of %llu. "
+                                 "Using geometry cylinder value of %ju. "
                                  "This value may be truncated for devices "
                                  "> 33.8 GB."),
-                               cxt->dev_path, cxt->geom.cylinders);
+                               cxt->dev_path, (uintmax_t) cxt->geom.cylinders);
                }
        } else
                ask_geom(cxt);