windows: fix format string attributes on MinGW

MinGW maps the "printf" format string archetype to the non-standard
MSVCRT functions, even if __USE_MINGW_ANSI_STDIO is defined and set
to 1. We need to use "gnu_printf" to use the format strings as provided
by vsnprintf and similar functions to get correct warnings.

Since "gnu_printf" isn't necessarily available on other GCC compatible
compilers (such as clang), do this only on MinGW.
This commit is contained in:
wm4 2012-01-31 08:32:06 +01:00 committed by Uoti Urpala
parent eebe9309ec
commit 25417a626d
3 changed files with 26 additions and 20 deletions

View File

@ -130,19 +130,15 @@ void mp_msg_init(void);
int mp_msg_test(int mod, int lev);
#include "config.h"
#include "mpcommon.h"
char *mp_gtext(const char *string);
void mp_msg_va(int mod, int lev, const char *format, va_list va);
#ifdef __GNUC__
void mp_msg(int mod, int lev, const char *format, ... ) __attribute__ ((format (printf, 3, 4)));
void mp_tmsg(int mod, int lev, const char *format, ... ) __attribute__ ((format (printf, 3, 4)));
static inline void mp_dbg(int mod, int lev, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
#else // not GNU C
void mp_msg(int mod, int lev, const char *format, ... );
void mp_tmsg(int mod, int lev, const char *format, ...)
#endif /* __GNUC__ */
void mp_msg(int mod, int lev, const char *format, ... ) PRINTF_ATTRIBUTE(3, 4);
void mp_tmsg(int mod, int lev, const char *format, ... ) PRINTF_ATTRIBUTE(3, 4);
static inline void mp_dbg(int mod, int lev, const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
static inline void mp_dbg(int mod, int lev, const char *format, ...)
{

View File

@ -31,6 +31,26 @@
#define MP_RESIZE_ARRAY(ctx, p, count) do { \
p = talloc_realloc_size((ctx), p, (count) * sizeof(p[0])); } while (0)
#ifdef __GNUC__
/** Use gcc attribute to check printf fns. a1 is the 1-based index of
* the parameter containing the format, and a2 the index of the first
* argument. **/
#ifdef __MINGW32__
// MinGW maps "printf" to the non-standard MSVCRT functions, even if
// __USE_MINGW_ANSI_STDIO is defined and set to 1. We need to use "gnu_printf",
// which isn't necessarily available on other GCC compatible compilers.
#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (gnu_printf, a1, a2)))
#else
#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (printf, a1, a2)))
#endif
#else
#define PRINTF_ATTRIBUTE(a1, a2)
#endif
extern const char *mplayer_version;
#endif /* MPLAYER_MPCOMMON_H */

View File

@ -29,6 +29,8 @@
#include <stdio.h>
#include <stdarg.h>
#include "mpcommon.h"
/* HACK: libsmbclient uses dynamically linked libtalloc.so which has
* identically named symbols. This name collision caused a crash under
* stream_smb when trying to play anything with smb://. This hack
@ -54,18 +56,6 @@ typedef void TALLOC_CTX;
#define TALLOC_DEPRECATED 0
#endif
#ifndef PRINTF_ATTRIBUTE
#if (__GNUC__ >= 3)
/** Use gcc attribute to check printf fns. a1 is the 1-based index of
* the parameter containing the format, and a2 the index of the first
* argument. Note that some gcc 2.x versions don't handle this
* properly **/
#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
#else
#define PRINTF_ATTRIBUTE(a1, a2)
#endif
#endif
/* try to make talloc_set_destructor() and talloc_steal() type safe,
if we have a recent gcc */
#if (__GNUC__ >= 3)