diff --git a/sc2/src/port.h b/sc2/src/port.h index c065e59a8..f9ce3c313 100644 --- a/sc2/src/port.h +++ b/sc2/src/port.h @@ -154,5 +154,22 @@ typedef unsigned int wint_t; # define SDL_IMAGE_INCLUDE(file) #endif /* SDL_IMAGE_DIR */ +// Mark a function as using printf-style function arguments, so that +// extra consistency checks can be made by the compiler. +// The first argument to PRINTF_FUNCTION and VPRINTF_FUNCTION is the +// index of the format string argument, the second is the index of +// the first argument which is specified in the format string (in the +// case of PRINTF_FUNCTION) or of the va_list argument (in the case of +// VPRINTF_FUNCTION). +#ifdef __GNUC__ +# define PRINTF_FUNCTION(formatArg, firstArg) \ + __attribute__((format(printf, formatArg, firstArg))) +# define VPRINTF_FUNCTION(formatArg, arglist) \ + __attribute__((format(printf, formatArg, 0))) +#else +# define PRINTF_FUNCTION(formatArg, firstArg) +# define VPRINTF_FUNCTION(formatArg, arglist) +#endif + #endif /* _PORT_H */ diff --git a/sc2/src/sc2code/libs/log/uqmlog.h b/sc2/src/sc2code/libs/log/uqmlog.h index 717c322f6..79bc79e22 100755 --- a/sc2/src/sc2code/libs/log/uqmlog.h +++ b/sc2/src/sc2code/libs/log/uqmlog.h @@ -44,10 +44,14 @@ typedef enum } log_Level; -extern void log_add (log_Level, const char *fmt, ...); -extern void log_addV (log_Level, const char *fmt, va_list); -extern void log_add_nothread (log_Level, const char *fmt, ...); -extern void log_add_nothreadV (log_Level, const char *fmt, va_list); +extern void log_add (log_Level, const char *fmt, ...) + PRINTF_FUNCTION(2, 3); +extern void log_addV (log_Level, const char *fmt, va_list) + VPRINTF_FUNCTION(2, 3); +extern void log_add_nothread (log_Level, const char *fmt, ...) + PRINTF_FUNCTION(2, 3); +extern void log_add_nothreadV (log_Level, const char *fmt, va_list) + VPRINTF_FUNCTION(2, 3); #endif /* _UQMLOG_H */