summaryrefslogtreecommitdiffstats
path: root/mpcommon.h
diff options
context:
space:
mode:
authorwm4 <wm4@mplayer2.org>2012-01-31 08:32:06 +0100
committerUoti Urpala <uau@mplayer2.org>2012-03-01 00:22:29 +0200
commit25417a626d0b9077bfbb940952f3858d7b8b549b (patch)
treee2f61063948b29a9e9fdb5c00fad8a571a367504 /mpcommon.h
parenteebe9309ecd70f86f0a52f09712db833df589206 (diff)
downloadmpv-25417a626d0b9077bfbb940952f3858d7b8b549b.tar.bz2
mpv-25417a626d0b9077bfbb940952f3858d7b8b549b.tar.xz
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.
Diffstat (limited to 'mpcommon.h')
-rw-r--r--mpcommon.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/mpcommon.h b/mpcommon.h
index fd520eacf6..2ff66fed40 100644
--- a/mpcommon.h
+++ b/mpcommon.h
@@ -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 */