Bug 1322463 - Replace snprintf/vsnprintf by SprintfLiteral/VsprintfLiteral for what clang plugin reports on Windows. r?ehsan
MozReview-Commit-ID: 2bFcM53uEPb
--- a/js/src/gc/Memory.cpp
+++ b/js/src/gc/Memory.cpp
@@ -9,16 +9,17 @@
#include "mozilla/Atomics.h"
#include "mozilla/TaggedAnonymousMemory.h"
#include "js/HeapAPI.h"
#include "vm/Runtime.h"
#if defined(XP_WIN)
+#include "mozilla/Sprintf.h"
#include "jswin.h"
#include <psapi.h>
#elif defined(SOLARIS)
#include <sys/mman.h>
#include <unistd.h>
@@ -848,17 +849,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)) {
- snprintf(sCrashReason, sizeof(sCrashReason),
+ SprintfLiteral(sCrashReason,
"MOZ_CRASH(VirtualProtect(PAGE_NOACCESS) failed! Error code: %u)", GetLastError());
MOZ_CRASH_ANNOTATE(sCrashReason);
MOZ_REALLY_CRASH();
}
MOZ_ASSERT(oldProtect == PAGE_READWRITE);
#else // assume Unix
if (mprotect(p, size, PROT_NONE))
MOZ_CRASH("mprotect(PROT_NONE) failed");
@@ -869,17 +870,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)) {
- snprintf(sCrashReason, sizeof(sCrashReason),
+ SprintfLiteral(sCrashReason,
"MOZ_CRASH(VirtualProtect(PAGE_READONLY) failed! Error code: %u)", GetLastError());
MOZ_CRASH_ANNOTATE(sCrashReason);
MOZ_REALLY_CRASH();
}
MOZ_ASSERT(oldProtect == PAGE_READWRITE);
#else // assume Unix
if (mprotect(p, size, PROT_READ))
MOZ_CRASH("mprotect(PROT_READ) failed");
@@ -890,17 +891,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)) {
- snprintf(sCrashReason, sizeof(sCrashReason),
+ SprintfLiteral(sCrashReason,
"MOZ_CRASH(VirtualProtect(PAGE_READWRITE) failed! Error code: %u)", GetLastError());
MOZ_CRASH_ANNOTATE(sCrashReason);
MOZ_REALLY_CRASH();
}
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");
--- a/mozglue/build/WindowsDllBlocklist.cpp
+++ b/mozglue/build/WindowsDllBlocklist.cpp
@@ -21,16 +21,17 @@
#pragma warning( push )
#pragma warning( disable : 4275 4530 ) // See msvc-stl-wrapper.template.h
#include <map>
#pragma warning( pop )
#include "nsAutoPtr.h"
#include "nsWindowsDllInterceptor.h"
+#include "mozilla/Sprintf.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/WindowsVersion.h"
#include "nsWindowsHelpers.h"
#include "WindowsDllBlocklist.h"
using namespace mozilla;
#define ALL_VERSIONS ((unsigned long long)-1LL)
@@ -255,18 +256,17 @@ static bool sUser32BeforeBlocklist;
// Duplicated from xpcom glue. Ideally this should be shared.
void
printf_stderr(const char *fmt, ...)
{
if (IsDebuggerPresent()) {
char buf[2048];
va_list args;
va_start(args, fmt);
- vsnprintf(buf, sizeof(buf), fmt, args);
- buf[sizeof(buf) - 1] = '\0';
+ VsprintfLiteral(buf, fmt, args);
va_end(args);
OutputDebugStringA(buf);
}
FILE *fp = _fdopen(_dup(2), "a");
if (!fp)
return;