libfdisk: add and fix __format__ attributes
Reported-by: Jan Pazdziora <jpazdziora@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
ea75960d6c
commit
fbae144212
|
@ -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();
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue