Skip to content

Commit 25417a6

Browse files
wm4Uoti Urpala
wm4
authored and
Uoti Urpala
committed
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.
1 parent eebe930 commit 25417a6

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

mp_msg.h

+4-8
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,15 @@ void mp_msg_init(void);
130130
int mp_msg_test(int mod, int lev);
131131

132132
#include "config.h"
133+
#include "mpcommon.h"
133134

134135
char *mp_gtext(const char *string);
135136

136137
void mp_msg_va(int mod, int lev, const char *format, va_list va);
137138

138-
#ifdef __GNUC__
139-
void mp_msg(int mod, int lev, const char *format, ... ) __attribute__ ((format (printf, 3, 4)));
140-
void mp_tmsg(int mod, int lev, const char *format, ... ) __attribute__ ((format (printf, 3, 4)));
141-
static inline void mp_dbg(int mod, int lev, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
142-
#else // not GNU C
143-
void mp_msg(int mod, int lev, const char *format, ... );
144-
void mp_tmsg(int mod, int lev, const char *format, ...)
145-
#endif /* __GNUC__ */
139+
void mp_msg(int mod, int lev, const char *format, ... ) PRINTF_ATTRIBUTE(3, 4);
140+
void mp_tmsg(int mod, int lev, const char *format, ... ) PRINTF_ATTRIBUTE(3, 4);
141+
static inline void mp_dbg(int mod, int lev, const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
146142

147143
static inline void mp_dbg(int mod, int lev, const char *format, ...)
148144
{

mpcommon.h

+20
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@
3131
#define MP_RESIZE_ARRAY(ctx, p, count) do { \
3232
p = talloc_realloc_size((ctx), p, (count) * sizeof(p[0])); } while (0)
3333

34+
#ifdef __GNUC__
35+
36+
/** Use gcc attribute to check printf fns. a1 is the 1-based index of
37+
* the parameter containing the format, and a2 the index of the first
38+
* argument. **/
39+
#ifdef __MINGW32__
40+
// MinGW maps "printf" to the non-standard MSVCRT functions, even if
41+
// __USE_MINGW_ANSI_STDIO is defined and set to 1. We need to use "gnu_printf",
42+
// which isn't necessarily available on other GCC compatible compilers.
43+
#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (gnu_printf, a1, a2)))
44+
#else
45+
#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (printf, a1, a2)))
46+
#endif
47+
48+
#else
49+
50+
#define PRINTF_ATTRIBUTE(a1, a2)
51+
52+
#endif
53+
3454
extern const char *mplayer_version;
3555

3656
#endif /* MPLAYER_MPCOMMON_H */

talloc.h

+2-12
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include <stdio.h>
3030
#include <stdarg.h>
3131

32+
#include "mpcommon.h"
33+
3234
/* HACK: libsmbclient uses dynamically linked libtalloc.so which has
3335
* identically named symbols. This name collision caused a crash under
3436
* stream_smb when trying to play anything with smb://. This hack
@@ -54,18 +56,6 @@ typedef void TALLOC_CTX;
5456
#define TALLOC_DEPRECATED 0
5557
#endif
5658

57-
#ifndef PRINTF_ATTRIBUTE
58-
#if (__GNUC__ >= 3)
59-
/** Use gcc attribute to check printf fns. a1 is the 1-based index of
60-
* the parameter containing the format, and a2 the index of the first
61-
* argument. Note that some gcc 2.x versions don't handle this
62-
* properly **/
63-
#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
64-
#else
65-
#define PRINTF_ATTRIBUTE(a1, a2)
66-
#endif
67-
#endif
68-
6959
/* try to make talloc_set_destructor() and talloc_steal() type safe,
7060
if we have a recent gcc */
7161
#if (__GNUC__ >= 3)

0 commit comments

Comments
 (0)