From 19a910468400ee1188c229dc0b4f68ec645a1df3 Mon Sep 17 00:00:00 2001 From: Ting-Yu Chou Date: Fri, 9 Dec 2016 09:47:19 +0800 Subject: [PATCH] Bug 1322463 - Replace snprintf/vsnprintf by SprintfLiteral/VsprintfLiteral for what clang plugin reports on Windows. r=Ehsan MozReview-Commit-ID: 2bFcM53uEPb --HG-- extra : rebase_source : 4e69d3f3f95c18bcbf731a17cb98fa456ddaa118 --- js/src/gc/Memory.cpp | 7 ++++--- mozglue/build/WindowsDllBlocklist.cpp | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/js/src/gc/Memory.cpp b/js/src/gc/Memory.cpp index 00f3c23e336b..c68b542224ed 100644 --- a/js/src/gc/Memory.cpp +++ b/js/src/gc/Memory.cpp @@ -14,6 +14,7 @@ #if defined(XP_WIN) +#include "mozilla/Sprintf.h" #include "jswin.h" #include @@ -853,7 +854,7 @@ ProtectPages(void* p, size_t size) #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(); @@ -874,7 +875,7 @@ MakePagesReadOnly(void* p, size_t size) #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(); @@ -895,7 +896,7 @@ UnprotectPages(void* p, size_t size) #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(); diff --git a/mozglue/build/WindowsDllBlocklist.cpp b/mozglue/build/WindowsDllBlocklist.cpp index 55761fee37ff..92d3170676ad 100644 --- a/mozglue/build/WindowsDllBlocklist.cpp +++ b/mozglue/build/WindowsDllBlocklist.cpp @@ -26,6 +26,7 @@ #include "nsAutoPtr.h" #include "nsWindowsDllInterceptor.h" +#include "mozilla/Sprintf.h" #include "mozilla/UniquePtr.h" #include "mozilla/WindowsVersion.h" #include "nsWindowsHelpers.h" @@ -260,8 +261,7 @@ printf_stderr(const char *fmt, ...) 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); }