From 4f6b38ca2cba4aaf49d88a689f48b4183e88f604 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 12 Feb 2008 10:29:48 +0100 Subject: [PATCH] Annotate printf-like functions with format checking attributes. --- lib/pci.h | 6 +++--- lib/types.h | 6 ++++++ pciutils.h | 2 +- setpci.c | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/pci.h b/lib/pci.h index d2c9ab6..1f1c7ef 100644 --- a/lib/pci.h +++ b/lib/pci.h @@ -52,9 +52,9 @@ struct pci_access { int debugging; /* Turn on debugging messages */ /* Functions you can override: */ - void (*error)(char *msg, ...); /* Write error message and quit */ - void (*warning)(char *msg, ...); /* Write a warning message */ - void (*debug)(char *msg, ...); /* Write a debugging message */ + void (*error)(char *msg, ...) PCI_PRINTF(1,2); /* Write error message and quit */ + void (*warning)(char *msg, ...) PCI_PRINTF(1,2); /* Write a warning message */ + void (*debug)(char *msg, ...) PCI_PRINTF(1,2); /* Write a debugging message */ struct pci_dev *devices; /* Devices found on this bus */ diff --git a/lib/types.h b/lib/types.h index f7ab470..3405bb9 100644 --- a/lib/types.h +++ b/lib/types.h @@ -57,3 +57,9 @@ typedef u32 pciaddr_t; #else #define PCIIRQ_FMT "%d" #endif + +#ifdef __GNUC__ +#define PCI_PRINTF(x,y) __attribute__((format(printf, x, y))) +#else +#define PCI_PRINTF(x,y) +#endif diff --git a/pciutils.h b/pciutils.h index 9408102..a1d1890 100644 --- a/pciutils.h +++ b/pciutils.h @@ -17,7 +17,7 @@ extern const char program_name[]; -void die(char *msg, ...) NONRET; +void die(char *msg, ...) NONRET PCI_PRINTF(1,2); void *xmalloc(unsigned int howmuch); void *xrealloc(void *ptr, unsigned int howmuch); int parse_generic_option(int i, struct pci_access *pacc, char *optarg); diff --git a/setpci.c b/setpci.c index fc10c1d..7ed0ac6 100644 --- a/setpci.c +++ b/setpci.c @@ -246,7 +246,7 @@ static const struct reg_name pci_reg_names[] = { { 0x00, 0, NULL } }; -static void NONRET +static void NONRET PCI_PRINTF(1,2) usage(char *msg, ...) { va_list args; -- 2.39.2