From 49d5594bd2b3f7940a40d5285369204dcece64f8 Mon Sep 17 00:00:00 2001 From: Richard Goedeken Date: Sun, 3 Mar 2019 11:02:59 -0800 Subject: [PATCH] add function attributes so GCC can find bugs in calls to string formatting functions with variadic arguments --- src/rdp.h | 12 ++++++++++-- src/rgl_debugger.cpp | 8 +++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/rdp.h b/src/rdp.h index 703704c..5575140 100644 --- a/src/rdp.h +++ b/src/rdp.h @@ -22,6 +22,12 @@ #ifndef _RDP_H_ #define _RDP_H_ +#if defined(__GNUC__) +#define ATTR_FMT(fmtpos, attrpos) __attribute__ ((format (printf, fmtpos, attrpos))) +#else +#define ATTR_FMT(fmtpos, attrpos) +#endif + #include #include #include @@ -247,7 +253,7 @@ int rdp_dasm(uint32_t * rdp_cmd_data, int rdp_cmd_cur, int length, char *buffer) void rdp_process_list(void); int rdp_store_list(void); -void rdp_log(m64p_msg_level level, const char *msg, ...); +void rdp_log(m64p_msg_level level, const char *msg, ...) ATTR_FMT(2,3); #ifdef RDP_DEBUG @@ -258,7 +264,9 @@ extern int rdp_dump; #define DUMP if (!rdp_dump) ; else LOG -static void LOG(const char * s, ...) +static void LOG(const char * s, ...) ATTR_FMT(1,2); + +void LOG(const char * s, ...) { va_list ap; va_start(ap, s); diff --git a/src/rgl_debugger.cpp b/src/rgl_debugger.cpp index 3d074ab..5725a56 100644 --- a/src/rgl_debugger.cpp +++ b/src/rgl_debugger.cpp @@ -24,6 +24,12 @@ #include "rdp.h" #include "rgl.h" +#if defined(__GNUC__) +#define ATTR_FMT(fmtpos, attrpos) __attribute__ ((format (printf, fmtpos, attrpos))) +#else +#define ATTR_FMT(fmtpos, attrpos) +#endif + static const char *saRGBText[] = { "PREV", "TEXEL0", "TEXEL1", "PRIM", @@ -176,7 +182,7 @@ void gglPrint(int x, int y, const char * text) //printf("%s\n", text); } -void gglPrintf(int x, int y, const char * s, ...) +void gglPrintf(int x, int y, const char * s, ...) ATTR_FMT(3,4) { char buf[1024]; va_list ap;