Re: [PATCH xserver] x86emu: Teach the debug code about varargs

2018-01-16 Thread Eric Anholt
Adam Jackson  writes:

> With -Wformat-nonliteral and a debug build you'd get yelled at here:
>
> ../hw/xfree86/x86emu/x86emu/debug.h:188:9: warning: format not a string 
> literal, argument types not checked [-Wformat-nonliteral]
>
> To fix this, rewrite the printf code to actually use varargs and the
> appropriate format attribute. All callers of DECODE_PRINTF() pass a
> string with no % specifiers, so we pass that as the argument to
> printf("%s"). For DECODE_PRINTF2() we just pass the args through.
>
> Signed-off-by: Adam Jackson 

Reviewed-by: Eric Anholt 


signature.asc
Description: PGP signature
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

[PATCH xserver] x86emu: Teach the debug code about varargs

2018-01-10 Thread Adam Jackson
With -Wformat-nonliteral and a debug build you'd get yelled at here:

../hw/xfree86/x86emu/x86emu/debug.h:188:9: warning: format not a string 
literal, argument types not checked [-Wformat-nonliteral]

To fix this, rewrite the printf code to actually use varargs and the
appropriate format attribute. All callers of DECODE_PRINTF() pass a
string with no % specifiers, so we pass that as the argument to
printf("%s"). For DECODE_PRINTF2() we just pass the args through.

Signed-off-by: Adam Jackson 
---
 hw/xfree86/x86emu/debug.c| 16 ++--
 hw/xfree86/x86emu/x86emu/debug.h |  7 +++
 2 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/hw/xfree86/x86emu/debug.c b/hw/xfree86/x86emu/debug.c
index 72a06ffb8..576ace55e 100644
--- a/hw/xfree86/x86emu/debug.c
+++ b/hw/xfree86/x86emu/debug.c
@@ -40,8 +40,8 @@
 #include "x86emu/x86emui.h"
 #include 
 #include 
-#ifndef NO_SYS_HEADERS
 #include 
+#ifndef NO_SYS_HEADERS
 #include 
 #endif
 
@@ -174,18 +174,14 @@ x86emu_inc_decoded_inst_len(int x)
 }
 
 void
-x86emu_decode_printf(const char *x)
-{
-sprintf(M.x86.decoded_buf + M.x86.enc_str_pos, "%s", x);
-M.x86.enc_str_pos += strlen(x);
-}
-
-void
-x86emu_decode_printf2(const char *x, int y)
+x86emu_decode_printf(const char *x, ...)
 {
+va_list ap;
 char temp[100];
 
-snprintf(temp, sizeof(temp), x, y);
+va_start(ap, x);
+vsnprintf(temp, sizeof(temp), x, ap);
+va_end(ap);
 sprintf(M.x86.decoded_buf + M.x86.enc_str_pos, "%s", temp);
 M.x86.enc_str_pos += strlen(temp);
 }
diff --git a/hw/xfree86/x86emu/x86emu/debug.h b/hw/xfree86/x86emu/x86emu/debug.h
index 385b804dd..1f04b7b65 100644
--- a/hw/xfree86/x86emu/x86emu/debug.h
+++ b/hw/xfree86/x86emu/x86emu/debug.h
@@ -102,9 +102,9 @@
 #ifdef DEBUG
 
 #define DECODE_PRINTF(x)   if (DEBUG_DECODE()) \
-   
x86emu_decode_printf(x)
+   
x86emu_decode_printf("%s",x)
 #define DECODE_PRINTF2(x,y)if (DEBUG_DECODE()) \
-   
x86emu_decode_printf2(x,y)
+   
x86emu_decode_printf(x,y)
 
 /*
  * The following allow us to look at the bytes of an instruction.  The
@@ -189,8 +189,7 @@ extern "C" {/* Use "C" linkage when in 
C++ mode */
 #endif
 
 extern void x86emu_inc_decoded_inst_len(int x);
-extern void x86emu_decode_printf(const char *x);
-extern void x86emu_decode_printf2(const char *x, int y);
+extern void x86emu_decode_printf(const char *x, ...) 
_X_ATTRIBUTE_PRINTF(1,2);
 extern void x86emu_just_disassemble(void);
 extern void x86emu_single_step(void);
 extern void x86emu_end_instr(void);
-- 
2.14.3

___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel