summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Jackson <ajax@redhat.com>2018-01-10 12:07:41 -0500
committerAdam Jackson <ajax@redhat.com>2018-01-16 16:08:38 -0500
commit15d91df47424127b9e8d0d73692e2196c79dd3fe (patch)
tree7cbb5bf447f61ca9c3628324ddc0886a331c8396
parent1274015186a8457c38c3b5dcc9965c62f1d2a7a6 (diff)
x86emu: Teach the debug code about varargs
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 <ajax@redhat.com> Reviewed-by: Eric Anholt <eric@anholt.net>
-rw-r--r--hw/xfree86/x86emu/debug.c16
-rw-r--r--hw/xfree86/x86emu/x86emu/debug.h7
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 <stdio.h>
#include <string.h>
-#ifndef NO_SYS_HEADERS
#include <stdarg.h>
+#ifndef NO_SYS_HEADERS
#include <stdlib.h>
#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);