From dcc59f4cf82062bf34c7d8c6b386f3342918860e Mon Sep 17 00:00:00 2001 From: meep-eep Date: Wed, 3 May 2006 21:17:12 +0000 Subject: [PATCH] Mark log functions as printf-type functions. git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2344 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/port.h | 17 +++++++++++++++++ sc2/src/sc2code/libs/log/uqmlog.h | 12 ++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) 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 */