Bug 1302163 - Change code to use SprintfLiteral instead of snprintf. r=ehsan

This commit is contained in:
Tom Schuster 2016-10-04 17:57:51 +02:00
parent 3cc61134b1
commit 774a8bf34d
26 changed files with 80 additions and 59 deletions

View File

@ -41,6 +41,7 @@
# include <binder/ProcessState.h>
#endif
#include "mozilla/Sprintf.h"
#include "mozilla/Telemetry.h"
#include "mozilla/WindowsDllBlocklist.h"
@ -123,7 +124,7 @@ static int do_main(int argc, char* argv[])
}
char appEnv[MAXPATHLEN];
snprintf(appEnv, MAXPATHLEN, "XUL_APP_FILE=%s", argv[2]);
SprintfLiteral(appEnv, "XUL_APP_FILE=%s", argv[2]);
if (putenv(strdup(appEnv))) {
Output("Couldn't set %s.\n", appEnv);
return 255;

View File

@ -39,6 +39,7 @@
#include "nsXPCOMPrivate.h" // for MAXPATHLEN and XPCOM_DLL
#include "mozilla/Sprintf.h"
#include "mozilla/Telemetry.h"
#include "mozilla/WindowsDllBlocklist.h"
@ -192,7 +193,7 @@ static int do_main(int argc, char* argv[], char* envp[], nsIFile *xreDirectory)
}
char appEnv[MAXPATHLEN];
snprintf(appEnv, MAXPATHLEN, "XUL_APP_FILE=%s", argv[2]);
SprintfLiteral(appEnv, "XUL_APP_FILE=%s", argv[2]);
if (putenv(strdup(appEnv))) {
Output("Couldn't set %s.\n", appEnv);
return 255;

View File

@ -32,6 +32,7 @@
#include "mozilla/plugins/BrowserStreamChild.h"
#include "mozilla/plugins/PluginStreamChild.h"
#include "mozilla/dom/CrashReporterChild.h"
#include "mozilla/Sprintf.h"
#include "mozilla/Unused.h"
#include "nsNPAPIPlugin.h"
@ -265,7 +266,7 @@ PluginModuleChild::InitForChrome(const std::string& aPluginFilename,
#if defined(XP_MACOSX)
const char* namePrefix = "Plugin Content";
char nameBuffer[80];
snprintf(nameBuffer, sizeof(nameBuffer), "%s (%s)", namePrefix, info.fName);
SprintfLiteral(nameBuffer, "%s (%s)", namePrefix, info.fName);
mozilla::plugins::PluginUtilsOSX::SetProcessName(nameBuffer);
#endif
pluginFile.FreePluginInfo(info);

View File

@ -15,6 +15,8 @@
#include "nsDebug.h"
#include "mozilla/Sprintf.h"
@interface CALayer (ContentsScale)
- (double)contentsScale;
- (void)setContentsScale:(double)scale;
@ -226,8 +228,7 @@ bool mozilla::plugins::PluginUtilsOSX::SetProcessName(const char* aProcessName)
objectForKey:(NSString *)kCFBundleNameKey];
char formattedName[1024];
snprintf(formattedName, sizeof(formattedName),
"%s %s", [currentName UTF8String], aProcessName);
SprintfLiteral(formattedName, "%s %s", [currentName UTF8String], aProcessName);
aProcessName = formattedName;

View File

@ -48,9 +48,8 @@ PaintCounter::~PaintCounter()
void
PaintCounter::Draw(Compositor* aCompositor, TimeDuration aPaintTime, TimeDuration aCompositeTime) {
const int buffer_size = 48;
char buffer[buffer_size];
snprintf(buffer, buffer_size, "P: %.2f C: %.2f",
char buffer[48];
SprintfLiteral(buffer, "P: %.2f C: %.2f",
aPaintTime.ToMilliseconds(),
aCompositeTime.ToMilliseconds());

View File

@ -9,6 +9,8 @@
#include "nsThreadUtils.h"
#include "nsContentUtils.h"
#include "mozilla/Sprintf.h"
#ifdef XP_WIN
#include <windows.h>
#endif
@ -20,10 +22,10 @@ static void DebugDump(const char* fmt, ...)
va_start(ap, fmt);
#ifdef XPWIN
_vsnprintf(buffer, sizeof(buffer), fmt, ap);
#else
vsnprintf(buffer, sizeof(buffer), fmt, ap);
#endif
buffer[sizeof(buffer)-1] = '\0';
#else
VsprintfLiteral(buffer, fmt, ap);
#endif
va_end(ap);
#ifdef XP_WIN
if (IsDebuggerPresent()) {

View File

@ -47,6 +47,7 @@
#include "mozilla/Atomics.h"
#include "mozilla/Attributes.h"
#include "mozilla/ProcessHangMonitor.h"
#include "mozilla/Sprintf.h"
#include "mozilla/UniquePtrExtensions.h"
#include "mozilla/Unused.h"
#include "AccessCheck.h"
@ -3528,7 +3529,7 @@ XPCJSContext::DescribeCustomObjects(JSObject* obj, const js::Class* clasp,
return false;
}
snprintf(name, sizeof(name), "JS Object (%s - %s)", clasp->name, si->GetJSClass()->name);
SprintfLiteral(name, "JS Object (%s - %s)", clasp->name, si->GetJSClass()->name);
return true;
}

View File

@ -9,6 +9,7 @@
#include "xpcprivate.h"
#include "jsprf.h"
#include "mozilla/DeferredFinalize.h"
#include "mozilla/Sprintf.h"
#include "mozilla/jsipc/CrossProcessObjectWrappers.h"
#include "nsCCUncollectableMarker.h"
#include "nsContentUtils.h"
@ -103,9 +104,9 @@ NS_CYCLE_COLLECTION_CLASSNAME(nsXPCWrappedJS)::Traverse
if (cb.WantDebugInfo()) {
char name[72];
if (tmp->GetClass())
snprintf(name, sizeof(name), "nsXPCWrappedJS (%s)", tmp->GetClass()->GetInterfaceName());
SprintfLiteral(name, "nsXPCWrappedJS (%s)", tmp->GetClass()->GetInterfaceName());
else
snprintf(name, sizeof(name), "nsXPCWrappedJS");
SprintfLiteral(name, "nsXPCWrappedJS");
cb.DescribeRefCountedNode(refcnt, name);
} else {
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(nsXPCWrappedJS, refcnt)

View File

@ -23,6 +23,7 @@
#include "mozilla/DeferredFinalize.h"
#include "mozilla/Likely.h"
#include "mozilla/Unused.h"
#include "mozilla/Sprintf.h"
#include "mozilla/dom/BindingUtils.h"
#include <algorithm>
@ -51,9 +52,9 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(XPCWrappedNative)
char name[72];
XPCNativeScriptableInfo* si = tmp->GetScriptableInfo();
if (si)
snprintf(name, sizeof(name), "XPCWrappedNative (%s)", si->GetJSClass()->name);
SprintfLiteral(name, "XPCWrappedNative (%s)", si->GetJSClass()->name);
else
snprintf(name, sizeof(name), "XPCWrappedNative");
SprintfLiteral(name, "XPCWrappedNative");
cb.DescribeRefCountedNode(tmp->mRefCnt.get(), name);
} else {

View File

@ -16,6 +16,7 @@
#include "mozilla/Assertions.h"
#include "mozilla/Move.h" // Pinch hitting for <utility> and std::move
#include "mozilla/Mutex.h"
#include "mozilla/Sprintf.h"
#include <vector>
extern "C" {
@ -33,7 +34,7 @@ static int ringbuffer_vlog(int facility,
// I could be evil and printf right into a std::string, but unless this
// shows up in profiling, it is not worth doing.
char temp[4096];
vsnprintf(temp, sizeof(temp), format, ap);
VsprintfLiteral(temp, format, ap);
mozilla::RLogRingBuffer::GetInstance()->Log(std::string(temp));
return 0;

View File

@ -15,6 +15,7 @@
#include "nsThreadUtils.h"
#include "mozilla/Logging.h"
#include "mozilla/Sprintf.h"
static PRLogModuleInfo *gLogModuleInfo = nullptr;
@ -83,7 +84,7 @@ void CSFLogV(CSFLogLevel priority, const char* sourceFile, int sourceLine, const
threadName = "";
}
vsnprintf(message, MAX_MESSAGE_LENGTH, format, args);
VsprintfLiteral(message, format, args);
MOZ_LOG(gLogModuleInfo, level, ("[%s|%s] %s:%d: %s",
threadName, tag, sourceFile, sourceLine,
message));

View File

@ -36,6 +36,7 @@
#include "nsIObserverService.h"
#include "nsIObserver.h"
#include "mozilla/Services.h"
#include "mozilla/Sprintf.h"
#include "nsProxyRelease.h"
#include "nsThread.h"
#include "nsThreadUtils.h"
@ -196,7 +197,7 @@ debug_printf(const char *format, ...)
#ifdef _WIN32
if (vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, format, ap) > 0) {
#else
if (vsnprintf(buffer, sizeof(buffer), format, ap) > 0) {
if (VsprintfLiteral(buffer, format, ap) > 0) {
#endif
PR_LogPrint("%s", buffer);
}

View File

@ -20,11 +20,12 @@
#include "nsString.h"
#include "mozilla/Logging.h"
#include "mozilla/Services.h"
#include "mozilla/Preferences.h"
#include "mozilla/FileUtils.h"
#include "mozilla/SHA1.h"
#include "mozilla/Base64.h"
#include "mozilla/FileUtils.h"
#include "mozilla/Preferences.h"
#include "mozilla/Services.h"
#include "mozilla/SHA1.h"
#include "mozilla/Sprintf.h"
#include "mozilla/Telemetry.h"
#ifdef MOZ_WIDGET_GONK
@ -139,7 +140,7 @@ void nsNotifyAddrListener::calculateNetworkId(void)
if (gw) {
/* create a string to search for in the arp table */
char searchfor[16];
snprintf(searchfor, sizeof(searchfor), "%d.%d.%d.%d",
SprintfLiteral(searchfor, "%d.%d.%d.%d",
gw & 0xff,
(gw >> 8) & 0xff,
(gw >> 16) & 0xff,

View File

@ -17,6 +17,7 @@
#include <unistd.h>
#include "mozilla/Assertions.h"
#include "mozilla/Sprintf.h"
#include "mozilla/Unused.h"
#include "sandbox/linux/system_headers/linux_syscalls.h"
@ -83,7 +84,7 @@ UnshareUserNamespace()
// current thread. However, CLONE_NEWUSER can be unshared only in a
// single-threaded process, so those are equivalent if we reach this
// point.
len = size_t(snprintf(buf, sizeof(buf), "%u %u 1\n", uid, uid));
len = size_t(SprintfLiteral(buf, "%u %u 1\n", uid, uid));
MOZ_ASSERT(len < sizeof(buf));
if (!WriteStringToFile("/proc/self/uid_map", buf, len)) {
MOZ_CRASH("Failed to write /proc/self/uid_map");
@ -91,7 +92,7 @@ UnshareUserNamespace()
Unused << WriteStringToFile("/proc/self/setgroups", "deny", 4);
len = size_t(snprintf(buf, sizeof(buf), "%u %u 1\n", gid, gid));
len = size_t(SprintfLiteral(buf, "%u %u 1\n", gid, gid));
MOZ_ASSERT(len < sizeof(buf));
if (!WriteStringToFile("/proc/self/gid_map", buf, len)) {
MOZ_CRASH("Failed to write /proc/self/gid_map");

View File

@ -29,6 +29,7 @@
#include "mozilla/DebugOnly.h"
#include "mozilla/Move.h"
#include "mozilla/NullPtr.h"
#include "mozilla/Sprintf.h"
#include "mozilla/ipc/FileDescriptor.h"
namespace mozilla {
@ -354,7 +355,7 @@ void
SandboxBroker::ThreadMain(void)
{
char threadName[16];
snprintf(threadName, sizeof(threadName), "FS Broker %d", mChildPid);
SprintfLiteral(threadName, "FS Broker %d", mChildPid);
PlatformThread::SetName(threadName);
// Permissive mode can only be enabled through an environment variable,

View File

@ -7,6 +7,7 @@
#include <stdio.h>
#include <gtk/gtk.h>
#include <unistd.h>
#include "mozilla/Sprintf.h"
#include "progressui.h"
#include "readstrings.h"
#include "errors.h"
@ -71,7 +72,7 @@ ShowProgressUI()
return 0;
char ini_path[PATH_MAX];
snprintf(ini_path, sizeof(ini_path), "%s.ini", sProgramPath);
SprintfLiteral(ini_path, "%s.ini", sProgramPath);
StringTable strings;
if (ReadStrings(ini_path, &strings) != OK)
@ -83,7 +84,7 @@ ShowProgressUI()
static GdkPixbuf *pixbuf;
char icon_path[PATH_MAX];
snprintf(icon_path, sizeof(icon_path), "%s.png", sProgramPath);
SprintfLiteral(icon_path, "%s.png", sProgramPath);
g_signal_connect(G_OBJECT(sWin), "delete_event",
G_CALLBACK(OnDeleteEvent), nullptr);

View File

@ -7,6 +7,7 @@
#import <Cocoa/Cocoa.h>
#include <stdio.h>
#include <unistd.h>
#include "mozilla/Sprintf.h"
#include "progressui.h"
#include "readstrings.h"
#include "errors.h"
@ -110,7 +111,7 @@ ShowProgressUI(bool indeterminate)
return 0;
char path[PATH_MAX];
snprintf(path, sizeof(path), "%s/updater.ini", sUpdatePath);
SprintfLiteral(path, "%s/updater.ini", sUpdatePath);
if (ReadStrings(path, &sLabels) != OK)
return -1;

View File

@ -18,6 +18,7 @@
#endif
#include "mozilla/ThreadLocal.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/Sprintf.h"
#include "PseudoStack.h"
#include "GeckoSampler.h"
#ifndef SPS_STANDALONE
@ -429,7 +430,7 @@ mozilla_sampler_log(const char *fmt, va_list args)
char buf[2048];
va_list argsCpy;
VARARGS_ASSIGN(argsCpy, args);
int required = vsnprintf(buf, sizeof(buf), fmt, argsCpy);
int required = VsprintfLiteral(buf, fmt, argsCpy);
va_end(argsCpy);
if (required < 0) {

View File

@ -11,6 +11,7 @@
#include <fcntl.h>
#include "mozilla/Assertions.h"
#include "mozilla/Sprintf.h"
#include "PlatformMacros.h"
#include "AutoObjectMapper.h"
@ -43,7 +44,7 @@ failedToMessage(void(*aLog)(const char*),
const char* aHowFailed, std::string aFileName)
{
char buf[300];
snprintf(buf, sizeof(buf), "AutoObjectMapper::Map: Failed to %s \'%s\'",
SprintfLiteral(buf, "AutoObjectMapper::Map: Failed to %s \'%s\'",
aHowFailed, aFileName.c_str());
buf[sizeof(buf)-1] = 0;
aLog(buf);

View File

@ -59,6 +59,7 @@
#include <vector>
#include "mozilla/Assertions.h"
#include "mozilla/Sprintf.h"
#include "LulPlatformMacros.h"
#include "LulCommonExt.h"
@ -359,7 +360,7 @@ bool LoadSymbols(const string& obj_file,
typedef typename ElfClass::Shdr Shdr;
char buf[500];
snprintf(buf, sizeof(buf), "LoadSymbols: BEGIN %s\n", obj_file.c_str());
SprintfLiteral(buf, "LoadSymbols: BEGIN %s\n", obj_file.c_str());
buf[sizeof(buf)-1] = 0;
log(buf);
@ -369,7 +370,7 @@ bool LoadSymbols(const string& obj_file,
GetOffset<ElfClass, Phdr>(elf_header, elf_header->e_phoff),
elf_header->e_phnum);
uintptr_t text_bias = ((uintptr_t)rx_avma) - loading_addr;
snprintf(buf, sizeof(buf),
SprintfLiteral(buf,
"LoadSymbols: rx_avma=%llx, text_bias=%llx",
(unsigned long long int)(uintptr_t)rx_avma,
(unsigned long long int)text_bias);
@ -434,7 +435,7 @@ bool LoadSymbols(const string& obj_file,
log("LoadSymbols: read CFI from .eh_frame");
}
snprintf(buf, sizeof(buf), "LoadSymbols: END %s\n", obj_file.c_str());
SprintfLiteral(buf, "LoadSymbols: END %s\n", obj_file.c_str());
buf[sizeof(buf)-1] = 0;
log(buf);

View File

@ -10,9 +10,10 @@
#include <stdlib.h>
#include <signal.h>
#include <stdarg.h>
#include "mozilla/ThreadLocal.h"
#include "mozilla/Assertions.h"
#include "mozilla/GuardObjects.h"
#include "mozilla/Sprintf.h"
#include "mozilla/ThreadLocal.h"
#include "mozilla/UniquePtr.h"
#ifndef SPS_STANDALONE
#include "nscore.h"
@ -443,8 +444,8 @@ public:
// We have to use seperate printf's because we're using
// the vargs.
::vsnprintf(buff, SAMPLER_MAX_STRING, aFormat, args);
::snprintf(mDest, SAMPLER_MAX_STRING, "%s %s", aInfo, buff);
VsprintfLiteral(buff, aFormat, args);
SprintfLiteral(mDest, "%s %s", aInfo, buff);
mHandle = mozilla_sampler_call_enter(mDest, aCategory, this, true, line);
va_end(args);

View File

@ -12,6 +12,7 @@
#include <notify.h>
#include "nsCocoaDebugUtils.h"
#include "mozilla/Preferences.h"
#include "mozilla/Sprintf.h"
int nsSandboxViolationSink::mNotifyToken = 0;
uint64_t nsSandboxViolationSink::mLastMsgReceived = 0;
@ -59,7 +60,7 @@ nsSandboxViolationSink::ViolationHandler()
// Only get reports that were generated very recently.
char query_time[30] = {0};
snprintf(query_time, sizeof(query_time), "%li", time(NULL) - 2);
SprintfLiteral(query_time, "%li", time(NULL) - 2);
asl_set_query(query, ASL_KEY_TIME, query_time,
ASL_QUERY_OP_NUMERIC | ASL_QUERY_OP_GREATER_EQUAL);
@ -74,7 +75,7 @@ nsSandboxViolationSink::ViolationHandler()
// be better to make the chrome process log all the other processes'
// violations.
char query_pid[20] = {0};
snprintf(query_pid, sizeof(query_pid), "%u", getpid());
SprintfLiteral(query_pid, "%u", getpid());
asl_set_query(query, ASL_KEY_REF_PID, query_pid, ASL_QUERY_OP_EQUAL);
}

View File

@ -12,6 +12,7 @@
#include "prprf.h"
#include "mozilla/SSE.h"
#include "mozilla/arm.h"
#include "mozilla/Sprintf.h"
#ifdef XP_WIN
#include <time.h>
@ -703,9 +704,8 @@ nsSystemInfo::Init()
#endif
if (gtkver_len <= 0) {
gtkver_len = snprintf(gtkver, sizeof(gtkver), "GTK %u.%u.%u",
gtk_major_version, gtk_minor_version,
gtk_micro_version);
gtkver_len = SprintfLiteral(gtkver, "GTK %u.%u.%u", gtk_major_version,
gtk_minor_version, gtk_micro_version);
}
nsAutoCString secondaryLibrary;

View File

@ -11,6 +11,8 @@
#include "nsXPCOMStrings.h"
#include "nsDebug.h"
#include "mozilla/Sprintf.h"
#include <stdio.h>
// nsAString
@ -521,9 +523,7 @@ nsAString::AppendInt(int aInt, int32_t aRadix)
}
char buf[20];
int len = snprintf(buf, sizeof(buf), fmt, aInt);
buf[sizeof(buf) - 1] = '\0';
int len = SprintfLiteral(buf, fmt, aInt);
Append(NS_ConvertASCIItoUTF16(buf, len));
}
@ -1001,9 +1001,7 @@ nsACString::AppendInt(int aInt, int32_t aRadix)
}
char buf[20];
int len = snprintf(buf, sizeof(buf), fmt, aInt);
buf[sizeof(buf) - 1] = '\0';
int len = SprintfLiteral(buf, fmt, aInt);
Append(buf, len);
}

View File

@ -15,6 +15,7 @@
#include <stdio.h>
#include "mozilla/FileUtils.h"
#include "mozilla/Sprintf.h"
using namespace mozilla;
@ -346,7 +347,7 @@ XPCOMGlueLoadXULFunctions(const nsDynamicFunctionLoad* aSymbols)
nsresult rv = NS_OK;
while (aSymbols->functionName) {
char buffer[512];
snprintf(buffer, sizeof(buffer), "%s", aSymbols->functionName);
SprintfLiteral(buffer, "%s", aSymbols->functionName);
*aSymbols->function = (NSFuncPtr)GetSymbol(sTop->libHandle, buffer);
if (!*aSymbols->function) {

View File

@ -10,6 +10,7 @@
#include "mozilla/ArrayUtils.h"
#include "mozilla/Attributes.h"
#include "mozilla/Sprintf.h"
#include <sys/types.h>
#include <sys/stat.h>
@ -1296,7 +1297,7 @@ GetDeviceName(int aDeviceMajor, int aDeviceMinor, nsACString& aDeviceName)
char mountinfoLine[kMountInfoLineLength];
char deviceNum[kMountInfoLineLength];
snprintf(deviceNum, kMountInfoLineLength, "%d:%d", aDeviceMajor, aDeviceMinor);
SprintfLiteral(deviceNum, "%d:%d", aDeviceMajor, aDeviceMinor);
FILE* f = fopen("/proc/self/mountinfo", "rt");
if (!f) {