mips_fulong2e: Detect format errors for function prom_set
PATCH 1/1 mips_fulong2e: Detect format errors for function prom_set
Add the necessary gcc attribute and fix the detected errors.
--- hw/mips_fulong2e.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
hw/mips_fulong2e.c +5 -3
@@ -77,6 +77,8 @@ static struct _loaderparams { } loaderparams;static void prom_set (uint32_t * prom_buf,int index,const char *string, ...) + __attribute__ ((format (gnu_printf,3 ,4 ))); +static void prom_set (uint32_t * prom_buf,int index,const char *string, ...) {va_list ap;int32_t table_addr;
@@ -141,13 +143,13 @@ static int64_t load_kernel (CPUState *env) prom_size =ENVP_NB_ENTRIES * (sizeof (int32_t ) +ENVP_ENTRY_SIZE ); prom_buf =qemu_malloc (prom_size); -prom_set (prom_buf, index++, loaderparams.kernel_filename); +prom_set (prom_buf, index++,"%s" , loaderparams.kernel_filename);if (initrd_size >0 ) { -prom_set (prom_buf, index++,"rd_start=0x" PRIx64" rd_size=%li %s" , +prom_set (prom_buf, index++,"rd_start=0x%" PRIx64" rd_size=%li %s" ,cpu_mips_phys_to_kseg0 (NULL , initrd_offset), initrd_size, loaderparams.kernel_cmdline); }else { -prom_set (prom_buf, index++, loaderparams.kernel_cmdline); +prom_set (prom_buf, index++,"%s" , loaderparams.kernel_cmdline); }/* Setup minimum environment variables */
Signature · 1 line
1.7.0.4
PATCH 1/1 mips_malta: Detect format errors for function prom_set
Add the necessary gcc attribute and fix the detected errors.
--- hw/mips_malta.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
hw/mips_malta.c +4 -2
@@ -684,6 +684,8 @@ static void write_bootloader (CPUState *env, uint8_t *base, }static void prom_set (uint32_t * prom_buf,int index,const char *string, ...) + __attribute__ ((format (gnu_printf,3 ,4 ))); +static void prom_set (uint32_t * prom_buf,int index,const char *string, ...) {va_list ap;int32_t table_addr;
@@ -750,13 +752,13 @@ static int64_t load_kernel(int big_endian) prom_size =ENVP_NB_ENTRIES * (sizeof (int32_t ) +ENVP_ENTRY_SIZE ); prom_buf =qemu_malloc (prom_size); -prom_set (prom_buf, prom_index++, loaderparams.kernel_filename); +prom_set (prom_buf, prom_index++,"%s" , loaderparams.kernel_filename);if (initrd_size >0 ) {prom_set (prom_buf, prom_index++,"rd_start=0x%" PRIx64" rd_size=%li %s" ,cpu_mips_phys_to_kseg0 (NULL , initrd_offset), initrd_size, loaderparams.kernel_cmdline); }else { -prom_set (prom_buf, prom_index++, loaderparams.kernel_cmdline); +prom_set (prom_buf, prom_index++,"%s" , loaderparams.kernel_cmdline); }prom_set (prom_buf, prom_index++,"memsize" );
Signature · 1 line
1.7.0.4
PATCH 1/2 Add support for gcc format attribute gnu_printf
Since version 4.4.x, gcc supports additional format attributes.
__attribute__ ((format (gnu_printf, 1, 2)))
should be used instead of
__attribute__ ((format (printf, 1, 2))because QEMU always uses standard format strings (even with mingw32).
For older compilers, we simply define gnu_printf = printf, so they work with the new format attribute, too.
--- configure | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
configure +11 -0
@@ -148,6 +148,17 @@ for flag in $gcc_flags; do fi done +# Check gnu_printf (supported by gcc >= 4.4.x). +cat > $TMPC << EOF +static void test(const char *format, ...) + __attribute__ ((format (gnu_printf, 1, 2))); +static void test(const char *format, ...) {} +int main(void) { test("\n"); return 0; } +EOF +if ! compile_prog "-Werror" ""; then + QEMU_CFLAGS="-Dgnu_printf=printf $QEMU_CFLAGS" +fi + # check that the C compiler works. cat > $TMPC <<EOF int main(void) {}
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 1/2] Add support for gcc format attribute gnu_printf
Quoted 22 lines · Stefan Weil
Since version 4.4.x, gcc supports additional format attributes.
__attribute__((format (gnu_printf, 1, 2)))
should be used instead of
__attribute__ ((format (printf, 1, 2))
because QEMU always uses standard format strings (even with mingw32).For older compilers, we simply define
gnu_printf= printf, so they work with the new format attribute, too.Signed-off-by Stefan Weil <[email protected]>---
configure | 11 +++++++++++1 files changed, 11 insertions(+), 0 deletions(-)configure +0
-0@@ -148,6 +148,17 @@ for flag in $gcc_flags; dofi
done
configure for flag in $gcc_flags; do · line 159
Quoted 9 lines
configure +9
-0+# Check gnu_printf (supported by gcc >= 4.4.x). +cat > $TMPC << EOF +static void test(const char *format, ...) + __attribute__ ((format (gnu_printf, 1, 2))); +static void test(const char *format, ...) {} +int main(void) { test("\n"); return 0; } +EOF +if ! compile_prog "-Werror" ""; then + QEMU_CFLAGS="-Dgnu_printf=printf $QEMU_CFLAGS"
This could cause problems, for example if system headers declared a function called gnu_printf.
I'd introduce CONFIG_GCC_FMT_ATTR_GNU_PRINTF and adjust GCC_FMT_ATTR definition based on that.
PATCH 1/1 Move macros GCC_ATTR and GCC_FMT_ATTR to common header file
By moving the definition of GCC_ATTR and GCC_FMT_ATTR from audio_int.h to qemu-common.h these macros are now generally available for further patches which add the gcc format attribute.
Newer gcc versions support format gnu_printf which is better suited for use in QEMU than format printf (QEMU always uses standard format strings (even with mingw32)).
--- audio/audio_int.h | 8 -------- qemu-common.h | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-)
audio/audio_int.h +0 -8
@@ -236,14 +236,6 @@ static inline int audio_ring_dist (int dst, int src, int len)return (dst >= src) ? (dst - src) : (len - src + dst); } -#if defined __GNUC__ -#define GCC_ATTR __attribute__ ((__unused__, format (gnu_printf, 1, 2))) -#define GCC_FMT_ATTR (n, m) __attribute__ ((format (gnu_printf, n, m))) -#else -#define GCC_ATTR /**/ -#define GCC_FMT_ATTR (n, m) -#endif - static void GCC_ATTR dolog (const char *fmt, ...) {va_list ap;
qemu-common.h +16 -0
@@ -70,6 +70,22 @@ struct iovec {#include <sys/uio.h> #endif +#if defined __GNUC__ +# if (__GNUC__ <4 ) || \ + defined(__GNUC_MINOR__) && (__GNUC__ = 4) && (__GNUC_MINOR__ < 4) +/* gcc versions before 4.4.x don't support gnu_printf, so use printf. */ +# define GCC_ATTR __attribute__((__unused__, format(printf, 1, 2))) +# define GCC_FMT_ATTR (n, m) __attribute__((format(printf, n, m))) +# else +/* Use gnu_printf when supported (qemu uses standard format strings). */ +# define GCC_ATTR __attribute__((__unused__, format(gnu_printf, 1, 2))) +# define GCC_FMT_ATTR (n, m) __attribute__((format(gnu_printf, n, m))) +# endif +#else +#define GCC_ATTR /**/ +#define GCC_FMT_ATTR (n, m) +#endif +#ifdef _WIN32#define fsync _commit#define lseek _lseeki64
Signature · 1 line
1.7.1
[Qemu-devel] Re: [PATCH] Move macros GCC_ATTR and GCC_FMT_ATTR to common header file
Please ignore this patch. It's wrong (= instead of ==). I'll send a fixed version.
Sorry,
Stefan
Am 20.09.2010 23:05, schrieb Stefan Weil:
Quoted 63 lines
By moving the definition of
GCC_ATTRandGCC_FMT_ATTRfromaudio_int.htoqemu-common.hthese macros are now generally available for further patches which add the gcc format attribute.Newer gcc versions support format
gnu_printfwhich is better suited for use in QEMU than format printf (QEMU always uses standard format strings (even with mingw32)).Cc Blue Swirl<[email protected]>Signed-off-by Stefan Weil<[email protected]>--- audio/audio_int.h | 8 -------- qemu-common.h | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-)audio/audio_int.h +0
-8@@ -236,14 +236,6 @@ static inline int audio_ring_dist (int dst, int src, int len)return (dst>= src) ? (dst - src) : (len - src + dst); } -#if defined __GNUC__ -#define GCC_ATTR __attribute__ ((__unused__, format (gnu_printf, 1, 2))) -#define GCC_FMT_ATTR (n, m) __attribute__ ((format (gnu_printf, n, m))) -#else -#define GCC_ATTR /**/ -#define GCC_FMT_ATTR (n, m) -#endif - static void GCC_ATTR dolog (const char *fmt, ...) {va_list ap;qemu-common.h +16
-0@@ -70,6 +70,22 @@ struct iovec {#include <sys/uio.h> #endif +#if defined __GNUC__ +# if (__GNUC__<4 ) || \ + defined(__GNUC_MINOR__)&& (__GNUC__ = 4)&& (__GNUC_MINOR__< 4) +/* gcc versions before 4.4.x don't support gnu_printf, so use printf. */ +# define GCC_ATTR __attribute__((__unused__, format(printf, 1, 2))) +# define GCC_FMT_ATTR (n, m) __attribute__((format(printf, n, m))) +# else +/* Use gnu_printf when supported (qemu uses standard format strings). */ +# define GCC_ATTR __attribute__((__unused__, format(gnu_printf, 1, 2))) +# define GCC_FMT_ATTR (n, m) __attribute__((format(gnu_printf, n, m))) +# endif +#else +#define GCC_ATTR /**/ +#define GCC_FMT_ATTR (n, m) +#endif +#ifdef _WIN32#define fsync _commit#define lseek _lseeki64
PATCH 1/1 Move macros GCC_ATTR and GCC_FMT_ATTR to common header file
By moving the definition of GCC_ATTR and GCC_FMT_ATTR from audio_int.h to qemu-common.h these macros are now generally available for further patches which add the gcc format attribute.
Newer gcc versions support format gnu_printf which is better suited for use in QEMU than format printf (QEMU always uses standard format strings (even with mingw32)).
V2: Use correct operator '==' (instead of '=')
--- audio/audio_int.h | 8 -------- qemu-common.h | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-)
audio/audio_int.h +0 -8
@@ -236,14 +236,6 @@ static inline int audio_ring_dist (int dst, int src, int len)return (dst >= src) ? (dst - src) : (len - src + dst); } -#if defined __GNUC__ -#define GCC_ATTR __attribute__ ((__unused__, format (gnu_printf, 1, 2))) -#define GCC_FMT_ATTR (n, m) __attribute__ ((format (gnu_printf, n, m))) -#else -#define GCC_ATTR /**/ -#define GCC_FMT_ATTR (n, m) -#endif - static void GCC_ATTR dolog (const char *fmt, ...) {va_list ap;
qemu-common.h +16 -0
@@ -70,6 +70,22 @@ struct iovec {#include <sys/uio.h> #endif +#if defined __GNUC__ +# if (__GNUC__ <4 ) || \ + defined(__GNUC_MINOR__) && (__GNUC__ ==4 ) && (__GNUC_MINOR__ <4 ) +/* gcc versions before 4.4.x don't support gnu_printf, so use printf. */ +# define GCC_ATTR __attribute__((__unused__, format(printf, 1, 2))) +# define GCC_FMT_ATTR (n, m) __attribute__((format(printf, n, m))) +# else +/* Use gnu_printf when supported (qemu uses standard format strings). */ +# define GCC_ATTR __attribute__((__unused__, format(gnu_printf, 1, 2))) +# define GCC_FMT_ATTR (n, m) __attribute__((format(gnu_printf, n, m))) +# endif +#else +#define GCC_ATTR /**/ +#define GCC_FMT_ATTR (n, m) +#endif +#ifdef _WIN32#define fsync _commit#define lseek _lseeki64
Signature · 1 line
1.7.1
[Qemu-devel] Re: [PATCH] Move macros GCC_ATTR and GCC_FMT_ATTR to common header file
Quoted 23 lines · Stefan Weil
By moving the definition of
GCC_ATTRandGCC_FMT_ATTRfromaudio_int.htoqemu-common.hthese macros are now generally available for further patches which add the gcc format attribute.Newer gcc versions support format
gnu_printfwhich is better suited for use in QEMU than format printf (QEMU always uses standard format strings (even with mingw32)).V2: Use correct operator '==' (instead of '=')
Cc Blue Swirl <[email protected]>Signed-off-by Stefan Weil <[email protected]>---
audio/audio_int.h | 8 --------qemu-common.h| 16 ++++++++++++++++2 files changed, 16 insertions(+), 8 deletions(-)audio/audio_int.h +0
-0
audio/audio_int.h static inline int audio_ring_dist (int dst, int src, int len) · line 241
Quoted 6 lines
audio/audio_int.h +0
-3@@ -236,14 +236,6 @@ static inline int audio_ring_dist (int dst, int src, int len) return (dst >= src) ? (dst - src) : (len - src + dst); } -#if defined __GNUC__ -#define GCC_ATTR __attribute__ ((__unused__, format (gnu_printf, 1, 2))) -#define GCC_FMT_ATTR (n, m) __attribute__ ((format (gnu_printf, n, m)))
The patch doesn't apply, the above lines do not match HEAD.
PATCH 1/1 Move macros GCC_ATTR and GCC_FMT_ATTR to common header file
By moving the definition of GCC_ATTR and GCC_FMT_ATTR from audio_int.h to qemu-common.h these macros are now generally available for further patches which add the gcc format attribute.
Newer gcc versions support format gnu_printf which is better suited for use in QEMU than format printf (QEMU always uses standard format strings (even with mingw32)).
V2: Use correct operator '==' (instead of '=')
--- audio/audio_int.h | 8 -------- qemu-common.h | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-)
audio/audio_int.h +0 -8
@@ -236,14 +236,6 @@ static inline int audio_ring_dist (int dst, int src, int len)return (dst >= src) ? (dst - src) : (len - src + dst); } -#if defined __GNUC__ -#define GCC_ATTR __attribute__ ((__unused__, __format__ (__printf__, 1, 2))) -#define GCC_FMT_ATTR (n, m) __attribute__ ((__format__ (__printf__, n, m))) -#else -#define GCC_ATTR /**/ -#define GCC_FMT_ATTR (n, m) -#endif - static void GCC_ATTR dolog (const char *fmt, ...) {va_list ap;
qemu-common.h +16 -0
@@ -70,6 +70,22 @@ struct iovec {#include <sys/uio.h> #endif +#if defined __GNUC__ +# if (__GNUC__ <4 ) || \ + defined(__GNUC_MINOR__) && (__GNUC__ ==4 ) && (__GNUC_MINOR__ <4 ) +/* gcc versions before 4.4.x don't support gnu_printf, so use printf. */ +# define GCC_ATTR __attribute__((__unused__, format(printf, 1, 2))) +# define GCC_FMT_ATTR (n, m) __attribute__((format(printf, n, m))) +# else +/* Use gnu_printf when supported (qemu uses standard format strings). */ +# define GCC_ATTR __attribute__((__unused__, format(gnu_printf, 1, 2))) +# define GCC_FMT_ATTR (n, m) __attribute__((format(gnu_printf, n, m))) +# endif +#else +#define GCC_ATTR /**/ +#define GCC_FMT_ATTR (n, m) +#endif +#ifdef _WIN32#define fsync _commit#define lseek _lseeki64
Signature · 1 line
1.7.1
Blue Swirl
Applied[Qemu-devel] Re: [PATCH] Move macros GCC_ATTR and GCC_FMT_ATTR to common header file
Thanks, applied.
Quoted 68 lines · Stefan Weil
By moving the definition of
GCC_ATTRandGCC_FMT_ATTRfromaudio_int.htoqemu-common.hthese macros are now generally available for further patches which add the gcc format attribute.Newer gcc versions support format
gnu_printfwhich is better suited for use in QEMU than format printf (QEMU always uses standard format strings (even with mingw32)).V2: Use correct operator '==' (instead of '=')
Cc Blue Swirl <[email protected]>Signed-off-by Stefan Weil <[email protected]>---
audio/audio_int.h | 8 --------qemu-common.h| 16 ++++++++++++++++2 files changed, 16 insertions(+), 8 deletions(-)audio/audio_int.h +0
-8@@ -236,14 +236,6 @@ static inline int audio_ring_dist (int dst, int src, int len) return (dst >= src) ? (dst - src) : (len - src + dst); } -#if defined __GNUC__ -#define GCC_ATTR __attribute__ ((__unused__, __format__ (__printf__, 1, 2))) -#define GCC_FMT_ATTR (n, m) __attribute__ ((__format__ (__printf__, n, m))) -#else -#define GCC_ATTR /**/ -#define GCC_FMT_ATTR (n, m) -#endif - static void GCC_ATTR dolog (const char *fmt, ...) { va_list ap;qemu-common.h +16
-1@@ -70,6 +70,22 @@ struct iovec { #include <sys/uio.h> #endif +#if defined __GNUC__ +# if (__GNUC__ <4 ) || \ + defined(__GNUC_MINOR__) && (__GNUC__ == 4) && (__GNUC_MINOR__ < 4) + /* gcc versions before 4.4.x don't support gnu_printf, so use printf. */ +# define GCC_ATTR __attribute__((__unused__, format(printf, 1, 2))) +# define GCC_FMT_ATTR(n, m) __attribute__((format(printf, n, m))) +# else + /* Use gnu_printf when supported (qemu uses standard format strings). */ +# define GCC_ATTR __attribute__((__unused__, format(gnu_printf, 1, 2))) +# define GCC_FMT_ATTR(n, m) __attribute__((format(gnu_printf, n, m))) +# endif +#else +#define GCC_ATTR /**/ +#define GCC_FMT_ATTR(n, m) +#endif + #ifdef _WIN32 #define fsync _commit #define lseek _lseeki64 --1.7.1
Re: [Qemu-devel] [PATCH 1/2] Add support for gcc format attribute gnu_printf
In reply to Blue SwirlAm 20.09.2010 21:18, schrieb Blue Swirl:
Quoted 37 lines · Stefan Weil
Quoted 23 lines
Since version 4.4.x, gcc supports additional format attributes.
__attribute__ ((format (gnu_printf, 1, 2))) should be used instead of __attribute__ ((format (printf, 1, 2))because QEMU always uses standard format strings (even with mingw32).
For older compilers, we simply define
gnu_printf= printf, so they work with the new format attribute, too.Signed-off-by Stefan Weil<[email protected]>--- configure | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)configure +0
-0@@ -148,6 +148,17 @@ for flag in $gcc_flags; do fi doneconfigure for flag in $gcc_flags; do · line 160
Quoted 10 lines
configure +9
-0+# Check gnu_printf (supported by gcc>= 4.4.x). +cat> $TMPC<< EOF +static void test(const char *format, ...) + __attribute__ ((format (gnu_printf, 1, 2))); +static void test(const char *format, ...) {} +int main(void) { test("\n"); return 0; } +EOF +if ! compile_prog "-Werror" ""; then + QEMU_CFLAGS="-Dgnu_printf=printf $QEMU_CFLAGS"This could cause problems, for example if system headers declared a function called
gnu_printf.
Quoted 4 lines
I'd introduce
CONFIG_GCC_FMT_ATTR_GNU_PRINTFand adjustGCC_FMT_ATTRdefinition based on that.
Thanks for your review. I'll send a new patch which goes into the direction which you suggested.
Instead of defining a new macro CONFIG_GCC_FMT_ATTR_GNU_PRINTF, my new patch checks the gcc version (gnu_printf was introduced with gcc 4.4). Like this, no changes to file configure are needed.
Regards
Stefan
PATCH 2/2 Use new gcc format attribute gnu_printf
In reply to Stefan WeilSince version 4.4.x, gcc supports additional format attributes.
__attribute__ ((format (gnu_printf, 1, 2)))
should be used instead of
__attribute__ ((format (printf, 1, 2))because QEMU always uses standard format strings (even with mingw32).
The patch replaces format attribute printf / __printf__ by gnu_printf.
It also removes an #ifdef __GNUC__ (not needed as long as we compile with gcc, and for non-gcc compilers we need more changes than this).
The gcc documentation uses format (not __format__), the majority in QEMU uses this shorter form, too. Therefore the patch also replaces __format__ by format.
Spacing was unified (again as in the gcc documentation).
--- audio/audio.h | 5 +---- audio/audio_int.h | 4 ++-- bsd-user/qemu.h | 2 +- cpu-all.h | 2 +- darwin-user/qemu.h | 2 +- hw/xen_backend.h | 2 +- linux-user/qemu.h | 2 +- monitor.h | 2 +- qemu-common.h | 2 +- qemu-error.h | 8 +++++--- qerror.h | 2 +- qjson.h | 2 +- 12 files changed, 17 insertions(+), 18 deletions(-)
audio/audio.h +1 -4
@@ -88,10 +88,7 @@ typedef struct QEMUAudioTimeStamp {void AUD_vlog (const char *cap,const char *fmt,va_list ap);void AUD_log (const char *cap,const char *fmt, ...) -#ifdef __GNUC__ - __attribute__ ((__format__ (__printf__,2 ,3 ))) -#endif - ; + __attribute__ ((format (gnu_printf,2 ,3 )));void AUD_help (void );void AUD_register_card (const char *name,QEMUSoundCard *card);
audio/audio_int.h +2 -2
@@ -237,8 +237,8 @@ static inline int audio_ring_dist (int dst, int src, int len) }#if defined __GNUC__ -#define GCC_ATTR __attribute__ ((__unused__, __format__ (__printf__, 1, 2))) -#define GCC_FMT_ATTR (n, m) __attribute__ ((__format__ (__printf__, n, m))) +#define GCC_ATTR __attribute__ ((__unused__, format (gnu_printf, 1, 2))) +#define GCC_FMT_ATTR (n, m) __attribute__ ((format (gnu_printf, n, m)))#else #define GCC_ATTR /**/ #define GCC_FMT_ATTR (n, m)
bsd-user/qemu.h +1 -1
@@ -139,7 +139,7 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,abi_long do_openbsd_syscall (void *cpu_env,int num,abi_long arg1,abi_long arg2,abi_long arg3,abi_long arg4,abi_long arg5,abi_long arg6); -void gemu_log (const char *fmt, ...) __attribute__((format (printf,1 ,2 ))); +void gemu_log (const char *fmt, ...) __attribute__((format (gnu_printf,1 ,2 ))); extern THREAD CPUState *thread_env;void cpu_loop (CPUState *env);char *target_strerror (int err);
cpu-all.h +1 -1
@@ -773,7 +773,7 @@ void cpu_dump_statistics (CPUState *env, FILE *f, int flags); void QEMU_NORETURN cpu_abort(CPUState *env, const char *fmt, ...) - __attribute__ ((__format__ (__printf__,2 ,3 ))); + __attribute__ ((format (gnu_printf,2 ,3 )));extern CPUState *first_cpu;extern CPUState *cpu_single_env;
darwin-user/qemu.h +1 -1
@@ -99,7 +99,7 @@ int do_sigaction(int sig, const struct sigaction *act, struct sigaction *oact);int do_sigaltstack (const struct sigaltstack *ss,struct sigaltstack *oss); -void gemu_log (const char *fmt, ...) __attribute__((format (printf,1 ,2 ))); +void gemu_log (const char *fmt, ...) __attribute__((format (gnu_printf,1 ,2 )));void qerror (const char *fmt, ...);void write_dt (void *ptr,unsigned long addr,unsigned long limit,int flags);
hw/xen_backend.h +1 -1
@@ -84,7 +84,7 @@ int xen_be_bind_evtchn(struct XenDevice *xendev);void xen_be_unbind_evtchn (struct XenDevice *xendev);int xen_be_send_notify (struct XenDevice *xendev);void xen_be_printf (struct XenDevice *xendev,int msg_level,const char *fmt, ...) - __attribute__ ((format (printf,3 ,4 ))); + __attribute__ ((format (gnu_printf,3 ,4 )));/* actual backend drivers */ extern struct XenDevOps xen_console_ops;/* xen_console.c */
linux-user/qemu.h +1 -1
@@ -186,7 +186,7 @@ void syscall_init(void);abi_long do_syscall (void *cpu_env,int num,abi_long arg1,abi_long arg2,abi_long arg3,abi_long arg4,abi_long arg5,abi_long arg6); -void gemu_log (const char *fmt, ...) __attribute__((format (printf,1 ,2 ))); +void gemu_log (const char *fmt, ...) __attribute__ ((format (gnu_printf,1 ,2 ))); extern THREAD CPUState *thread_env;void cpu_loop (CPUState *env);char *target_strerror (int err);
monitor.h +1 -1
@@ -51,7 +51,7 @@ int monitor_get_fd(Monitor *mon, const char *fdname);void monitor_vprintf (Monitor *mon,const char *fmt,va_list ap);void monitor_printf (Monitor *mon,const char *fmt, ...) - __attribute__ ((__format__ (__printf__,2 ,3 ))); + __attribute__ ((format (gnu_printf,2 ,3 )));void monitor_print_filename (Monitor *mon,const char *filename);void monitor_flush (Monitor *mon);
qemu-common.h +1 -1
@@ -181,7 +181,7 @@ int qemu_pipe(int pipefd[2]);/* Error handling. */ void QEMU_NORETURN hw_error(const char *fmt, ...) - __attribute__ ((__format__ (__printf__,1 ,2 ))); + __attribute__ ((format (gnu_printf,1 ,2 )));/* IO callbacks. */ typedef void IOReadHandler (void *opaque,const uint8_t *buf,int size);
qemu-error.h +5 -3
@@ -31,11 +31,13 @@ void loc_set_cmdline(char **argv, int idx, int cnt);void loc_set_file (const char *fname,int lno);void error_vprintf (const char *fmt,va_list ap); -void error_printf (const char *fmt, ...) __attribute__ ((format (printf,1 ,2 ))); +void error_printf (const char *fmt, ...) + __attribute__ ((format (gnu_printf,1 ,2 )));void error_printf_unless_qmp (const char *fmt, ...) - __attribute__ ((format (printf,1 ,2 ))); + __attribute__ ((format (gnu_printf,1 ,2 )));void error_print_loc (void );void error_set_progname (const char *argv0); -void error_report (const char *fmt, ...) __attribute__ ((format (printf,1 ,2 ))); +void error_report (const char *fmt, ...) + __attribute__ ((format (gnu_printf,1 ,2 )));#endif
qerror.h +1 -1
@@ -39,7 +39,7 @@ QString *qerror_human(const QError *qerror);void qerror_print (QError *qerror);void qerror_report_internal (const char *file,int linenr,const char *func,const char *fmt, ...) - __attribute__ ((format (printf,4 ,5 ))); + __attribute__ ((format (gnu_printf,4 ,5 )));#define qerror_report (fmt, ...) \ qerror_report_internal(__FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__)QError *qobject_to_qerror (const QObject *obj);
qjson.h +1 -1
@@ -20,7 +20,7 @@QObject *qobject_from_json (const char *string);QObject *qobject_from_jsonf (const char *string, ...) - __attribute__((__format__ (__printf__,1 ,2 ))); + __attribute__((format (gnu_printf,1 ,2 )));QObject *qobject_from_jsonv (const char *string,va_list *ap);QString *qobject_to_json (const QObject *obj);
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 2/2] Use new gcc format attribute gnu_printf
Quoted 8 lines · Stefan Weil
Since version 4.4.x, gcc supports additional format attributes.
__attribute__((format (gnu_printf, 1, 2)))
should be used instead of
__attribute__ ((format (printf, 1, 2))
because QEMU always uses standard format strings (even with mingw32).The patch replaces format attribute printf /
__printf__bygnu_printf.
Quoted 8 lines
It also removes an #ifdef
__GNUC__(not needed as long as we compile with gcc, and for non-gcc compilers we need more changes than this).The gcc documentation uses format (not
__format__), the majority in QEMU uses this shorter form, too. Therefore the patch also replaces__format__by format.Spacing was unified (again as in the gcc documentation).
Please avoid GNU style spacing. This is C, not LISP.
Quoted 37 lines
Signed-off-by Stefan Weil <[email protected]>---
audio/audio.h | 5 +----
audio/audio_int.h | 4 ++--
bsd-user/qemu.h | 2 +-
cpu-all.h | 2 +-
darwin-user/qemu.h | 2 +-
hw/xen_backend.h | 2 +-
linux-user/qemu.h | 2 +-
monitor.h | 2 +-
qemu-common.h | 2 +-
qemu-error.h | 8 +++++---
qerror.h | 2 +-
qjson.h | 2 +-12 files changed, 17 insertions(+), 18 deletions(-)audio/audio.h +1
-4@@ -88,10 +88,7 @@ typedef struct QEMUAudioTimeStamp { void AUD_vlog (const char *cap, const char *fmt, va_list ap); void AUD_log (const char *cap, const char *fmt, ...) -#ifdef __GNUC__ - __attribute__ ((__format__ (__printf__, 2, 3))) -#endif - ; + __attribute__ ((format (gnu_printf, 2, 3))); void AUD_help (void); void AUD_register_card (const char *name, QEMUSoundCard *card);audio/audio_int.h +0
-0
audio/audio_int.h static inline int audio_ring_dist (int dst, int src, int len) · line 241
Quoted 7 lines
audio/audio_int.h +2
-2@@ -237,8 +237,8 @@ static inline int audio_ring_dist (int dst, int src, int len) } #if defined __GNUC__ -#define GCC_ATTR __attribute__ ((__unused__, __format__ (__printf__, 1, 2))) -#define GCC_FMT_ATTR (n, m) __attribute__ ((__format__ (__printf__, n, m))) +#define GCC_ATTR __attribute__ ((__unused__, format (gnu_printf, 1, 2))) +#define GCC_FMT_ATTR (n, m) __attribute__ ((format (gnu_printf, n, m)))
I'd rather move this macro to a central header and converting instead users of other syntax. The macro could be defined differently depending on whether gnu_printf is supported or not. Then we would not need any -Dgnu_printf=printf in 1/2, which can cause problems.
Re: [Qemu-devel] [PATCH] mips_malta: Detect format errors for function prom_set
In reply to Stefan WeilQuoted 1 line · Stefan Weil
Add the necessary gcc attribute and fix the detected errors.
This is identical to fulong patch, so my comments on that one apply also here.
Quoted 41 lines
Cc Aurelien Jarno <[email protected]>Signed-off-by Stefan Weil <[email protected]>---
hw/mips_malta.c | 6 ++++--1 files changed, 4 insertions(+), 2 deletions(-)hw/mips_malta.c +4
-3@@ -684,6 +684,8 @@ static void write_bootloader (CPUState *env, uint8_t *base, } static void prom_set(uint32_t* prom_buf, int index, const char *string, ...) + __attribute__ ((format (gnu_printf, 3, 4))); +static void prom_set (uint32_t * prom_buf,int index,const char *string, ...) { va_list ap; int32_t table_addr;@@ -750,13 +752,13 @@ static int64_t load_kernel(int big_endian) prom_size = ENVP_NB_ENTRIES * (sizeof(int32_t) + ENVP_ENTRY_SIZE); prom_buf = qemu_malloc(prom_size); - prom_set(prom_buf, prom_index++, loaderparams.kernel_filename); + prom_set(prom_buf, prom_index++, "%s", loaderparams.kernel_filename); if (initrd_size > 0) { prom_set(prom_buf, prom_index++, "rd_start=0x%" PRIx64 " rd_size=%li %s", cpu_mips_phys_to_kseg0(NULL, initrd_offset), initrd_size, loaderparams.kernel_cmdline); } else { - prom_set(prom_buf, prom_index++, loaderparams.kernel_cmdline); + prom_set(prom_buf, prom_index++, "%s", loaderparams.kernel_cmdline); } prom_set(prom_buf, prom_index++, "memsize"); --1.7.0.4
Quoted 1 line · Stefan Weil
Add the necessary gcc attribute and fix the detected errors.
The fixes are correct, so those parts could be applied.
However the gnu_printf part will break with older compilers unless 1/2 is applied first. That part should also use GCC_FMT_ATTR macro. Please split the patch.
Quoted 42 lines
Cc Aurelien Jarno <[email protected]>Signed-off-by Stefan Weil <[email protected]>---
hw/mips_fulong2e.c | 8 +++++---1 files changed, 5 insertions(+), 3 deletions(-)hw/mips_fulong2e.c +5
-4@@ -77,6 +77,8 @@ static struct _loaderparams { } loaderparams; static void prom_set(uint32_t* prom_buf, int index, const char *string, ...) + __attribute__ ((format (gnu_printf, 3, 4))); +static void prom_set (uint32_t * prom_buf,int index,const char *string, ...) { va_list ap; int32_t table_addr;@@ -141,13 +143,13 @@ static int64_t load_kernel (CPUState *env) prom_size = ENVP_NB_ENTRIES * (sizeof(int32_t) + ENVP_ENTRY_SIZE); prom_buf = qemu_malloc(prom_size); - prom_set(prom_buf, index++, loaderparams.kernel_filename); + prom_set(prom_buf, index++, "%s", loaderparams.kernel_filename); if (initrd_size > 0) { - prom_set(prom_buf, index++, "rd_start=0x" PRIx64 " rd_size=%li %s", + prom_set(prom_buf, index++, "rd_start=0x%" PRIx64 " rd_size=%li %s", cpu_mips_phys_to_kseg0(NULL, initrd_offset), initrd_size, loaderparams.kernel_cmdline); } else { - prom_set(prom_buf, index++, loaderparams.kernel_cmdline); + prom_set(prom_buf, index++, "%s", loaderparams.kernel_cmdline); } /* Setup minimum environment variables */ --1.7.0.4
PATCH 1/2 mips_fulong2e: Fix format strings
Fix two compiler warnings (when format attribute is applied) and one error (missing %) in format strings.
--- hw/mips_fulong2e.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
hw/mips_fulong2e.c +3 -3
@@ -141,13 +141,13 @@ static int64_t load_kernel (CPUState *env) prom_size =ENVP_NB_ENTRIES * (sizeof (int32_t ) +ENVP_ENTRY_SIZE ); prom_buf =qemu_malloc (prom_size); -prom_set (prom_buf, index++, loaderparams.kernel_filename); +prom_set (prom_buf, index++,"%s" , loaderparams.kernel_filename);if (initrd_size >0 ) { -prom_set (prom_buf, index++,"rd_start=0x" PRIx64" rd_size=%li %s" , +prom_set (prom_buf, index++,"rd_start=0x%" PRIx64" rd_size=%li %s" ,cpu_mips_phys_to_kseg0 (NULL , initrd_offset), initrd_size, loaderparams.kernel_cmdline); }else { -prom_set (prom_buf, index++, loaderparams.kernel_cmdline); +prom_set (prom_buf, index++,"%s" , loaderparams.kernel_cmdline); }/* Setup minimum environment variables */
Signature · 1 line
1.7.1
Blue Swirl
Applied[Qemu-devel] Re: [PATCH 1/2] mips_fulong2e: Fix format strings
Thanks, applied.
Quoted 35 lines · Stefan Weil
Fix two compiler warnings (when format attribute is applied) and one error (missing %) in format strings.
Cc Aurelien Jarno <[email protected]>Cc Blue Swirl <[email protected]>Signed-off-by Stefan Weil <[email protected]>---
hw/mips_fulong2e.c | 6 +++---1 files changed, 3 insertions(+), 3 deletions(-)hw/mips_fulong2e.c +3
-4@@ -141,13 +141,13 @@ static int64_t load_kernel (CPUState *env) prom_size = ENVP_NB_ENTRIES * (sizeof(int32_t) + ENVP_ENTRY_SIZE); prom_buf = qemu_malloc(prom_size); - prom_set(prom_buf, index++, loaderparams.kernel_filename); + prom_set(prom_buf, index++, "%s", loaderparams.kernel_filename); if (initrd_size > 0) { - prom_set(prom_buf, index++, "rd_start=0x" PRIx64 " rd_size=%li %s", + prom_set(prom_buf, index++, "rd_start=0x%" PRIx64 " rd_size=%li %s", cpu_mips_phys_to_kseg0(NULL, initrd_offset), initrd_size, loaderparams.kernel_cmdline); } else { - prom_set(prom_buf, index++, loaderparams.kernel_cmdline); + prom_set(prom_buf, index++, "%s", loaderparams.kernel_cmdline); } /* Setup minimum environment variables */ --1.7.1
PATCH 2/2 mips_malta: Fix format strings
In reply to Blue SwirlFix two compiler warnings (when format attribute is applied).
--- hw/mips_malta.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
hw/mips_malta.c +2 -2
@@ -728,13 +728,13 @@ static int64_t load_kernel (void) prom_size =ENVP_NB_ENTRIES * (sizeof (int32_t ) +ENVP_ENTRY_SIZE ); prom_buf =qemu_malloc (prom_size); -prom_set (prom_buf, prom_index++, loaderparams.kernel_filename); +prom_set (prom_buf, prom_index++,"%s" , loaderparams.kernel_filename);if (initrd_size >0 ) {prom_set (prom_buf, prom_index++,"rd_start=0x%" PRIx64" rd_size=%li %s" ,cpu_mips_phys_to_kseg0 (NULL , initrd_offset), initrd_size, loaderparams.kernel_cmdline); }else { -prom_set (prom_buf, prom_index++, loaderparams.kernel_cmdline); +prom_set (prom_buf, prom_index++,"%s" , loaderparams.kernel_cmdline); }prom_set (prom_buf, prom_index++,"memsize" );
Signature · 1 line
1.7.1
Blue Swirl
Applied[Qemu-devel] Re: [PATCH 2/2] mips_malta: Fix format strings
Thanks, applied.
Quoted 33 lines · Stefan Weil
Fix two compiler warnings (when format attribute is applied).
Cc Aurelien Jarno <[email protected]>Cc Blue Swirl <[email protected]>Signed-off-by Stefan Weil <[email protected]>---
hw/mips_malta.c | 4 ++--1 files changed, 2 insertions(+), 2 deletions(-)hw/mips_malta.c +2
-3@@ -728,13 +728,13 @@ static int64_t load_kernel (void) prom_size = ENVP_NB_ENTRIES * (sizeof(int32_t) + ENVP_ENTRY_SIZE); prom_buf = qemu_malloc(prom_size); - prom_set(prom_buf, prom_index++, loaderparams.kernel_filename); + prom_set(prom_buf, prom_index++, "%s", loaderparams.kernel_filename); if (initrd_size > 0) { prom_set(prom_buf, prom_index++, "rd_start=0x%" PRIx64 " rd_size=%li %s", cpu_mips_phys_to_kseg0(NULL, initrd_offset), initrd_size, loaderparams.kernel_cmdline); } else { - prom_set(prom_buf, prom_index++, loaderparams.kernel_cmdline); + prom_set(prom_buf, prom_index++, "%s", loaderparams.kernel_cmdline); } prom_set(prom_buf, prom_index++, "memsize"); --1.7.1