Bug 1331349 Fix printf formatting errors in MinGW compilation
MozReview-Commit-ID: A4PMABfxzez
--- a/js/src/gc/Memory.cpp
+++ b/js/src/gc/Memory.cpp
@@ -847,17 +847,17 @@ void
ProtectPages(void* p, size_t size)
{
MOZ_ASSERT(size % pageSize == 0);
MOZ_RELEASE_ASSERT(size > 0);
MOZ_RELEASE_ASSERT(p);
#if defined(XP_WIN)
DWORD oldProtect;
if (!VirtualProtect(p, size, PAGE_NOACCESS, &oldProtect)) {
- MOZ_CRASH_UNSAFE_PRINTF("VirtualProtect(PAGE_NOACCESS) failed! Error code: %u",
+ MOZ_CRASH_UNSAFE_PRINTF("VirtualProtect(PAGE_NOACCESS) failed! Error code: %lu",
GetLastError());
}
MOZ_ASSERT(oldProtect == PAGE_READWRITE);
#else // assume Unix
if (mprotect(p, size, PROT_NONE))
MOZ_CRASH("mprotect(PROT_NONE) failed");
#endif
}
@@ -866,17 +866,17 @@ void
MakePagesReadOnly(void* p, size_t size)
{
MOZ_ASSERT(size % pageSize == 0);
MOZ_RELEASE_ASSERT(size > 0);
MOZ_RELEASE_ASSERT(p);
#if defined(XP_WIN)
DWORD oldProtect;
if (!VirtualProtect(p, size, PAGE_READONLY, &oldProtect)) {
- MOZ_CRASH_UNSAFE_PRINTF("VirtualProtect(PAGE_READONLY) failed! Error code: %u",
+ MOZ_CRASH_UNSAFE_PRINTF("VirtualProtect(PAGE_READONLY) failed! Error code: %lu",
GetLastError());
}
MOZ_ASSERT(oldProtect == PAGE_READWRITE);
#else // assume Unix
if (mprotect(p, size, PROT_READ))
MOZ_CRASH("mprotect(PROT_READ) failed");
#endif
}
@@ -885,17 +885,17 @@ void
UnprotectPages(void* p, size_t size)
{
MOZ_ASSERT(size % pageSize == 0);
MOZ_RELEASE_ASSERT(size > 0);
MOZ_RELEASE_ASSERT(p);
#if defined(XP_WIN)
DWORD oldProtect;
if (!VirtualProtect(p, size, PAGE_READWRITE, &oldProtect)) {
- MOZ_CRASH_UNSAFE_PRINTF("VirtualProtect(PAGE_READWRITE) failed! Error code: %u",
+ MOZ_CRASH_UNSAFE_PRINTF("VirtualProtect(PAGE_READWRITE) failed! Error code: %lu",
GetLastError());
}
MOZ_ASSERT(oldProtect == PAGE_NOACCESS || oldProtect == PAGE_READONLY);
#else // assume Unix
if (mprotect(p, size, PROT_READ | PROT_WRITE))
MOZ_CRASH("mprotect(PROT_READ | PROT_WRITE) failed");
#endif
}
--- a/media/libstagefright/system/core/include/android/log.h
+++ b/media/libstagefright/system/core/include/android/log.h
@@ -92,17 +92,19 @@ typedef enum android_LogPriority {
* Send a simple string to the log.
*/
int __android_log_write(int prio, const char *tag, const char *text);
/*
* Send a formatted string to the log, used like printf(fmt,...)
*/
int __android_log_print(int prio, const char *tag, const char *fmt, ...)
-#if defined(__GNUC__)
+#if defined(__MINGW32__)
+ __attribute__ ((format(__MINGW_PRINTF_FORMAT, 3, 4)))
+#elif defined(__GNUC__)
__attribute__ ((format(printf, 3, 4)))
#endif
;
/*
* A variant of __android_log_print() that takes a va_list to list
* additional parameters.
*/
--- a/media/libstagefright/system/core/include/utils/String8.h
+++ b/media/libstagefright/system/core/include/utils/String8.h
@@ -59,17 +59,22 @@ public:
explicit String8(const char16_t* o);
explicit String8(const char16_t* o, size_t numChars);
explicit String8(const char32_t* o);
explicit String8(const char32_t* o, size_t numChars);
~String8();
static inline const String8 empty();
- static String8 format(const char* fmt, ...) __attribute__((format (printf, 1, 2)));
+ static String8 format(const char* fmt, ...)
+#ifdef __MINGW32__
+ __attribute__((format (__MINGW_PRINTF_FORMAT, 1, 2)));
+#else
+ __attribute__((format (printf, 1, 2)));
+#endif
static String8 formatV(const char* fmt, va_list args);
inline const char* string() const;
inline size_t size() const;
inline size_t length() const;
inline size_t bytes() const;
inline bool isEmpty() const;
--- a/mfbt/Attributes.h
+++ b/mfbt/Attributes.h
@@ -626,17 +626,25 @@
* However, if "print_something" were a non-static member function,
* then the annotation would be:
* MOZ_FORMAT_PRINTF(3, 4)
*
* Note that the checking is limited to standards-conforming
* printf-likes, and in particular this should not be used for
* PR_snprintf and friends, which are "printf-like" but which assign
* different meanings to the various formats.
+ *
+ * MinGW requires special handling due to different format specifiers
+ * on different platforms. The macro __MINGW_PRINTF_FORMAT maps to
+ * either gnu_printf or ms_printf depending on where we are compiling
+ * to avoid warnings on format specifiers that are legal.
*/
-#ifdef __GNUC__
+#ifdef __MINGW32__
+#define MOZ_FORMAT_PRINTF(stringIndex, firstToCheck) \
+ __attribute__ ((format (__MINGW_PRINTF_FORMAT, stringIndex, firstToCheck)))
+#elif __GNUC__
#define MOZ_FORMAT_PRINTF(stringIndex, firstToCheck) \
__attribute__ ((format (printf, stringIndex, firstToCheck)))
#else
#define MOZ_FORMAT_PRINTF(stringIndex, firstToCheck)
#endif
#endif /* mozilla_Attributes_h */