Bug 1239941 - Copy va_list before using it in LogModuleManager::Print. r=froydnj
authorEric Rahm <erahm@mozilla.com>
Fri, 15 Jan 2016 10:14:26 -0800
changeset 280220 1e81d89a1c98c233989d675ce85b07c2b4887d3a
parent 280219 6ce37c1907039d86eac031b0a6a03e2b3da78c11
child 280221 ad017d0208ef846761e835eabcc247dd64bae24a
push id29906
push userryanvm@gmail.com
push dateSun, 17 Jan 2016 19:40:11 +0000
treeherdermozilla-central@b92f5032b4fd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1239941
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1239941 - Copy va_list before using it in LogModuleManager::Print. r=froydnj
xpcom/base/Logging.cpp
--- a/xpcom/base/Logging.cpp
+++ b/xpcom/base/Logging.cpp
@@ -140,17 +140,21 @@ public:
   {
     const size_t kBuffSize = 1024;
     char buff[kBuffSize];
 
     char* buffToWrite = buff;
 
     // For backwards compat we need to use the NSPR format string versions
     // of sprintf and friends and then hand off to printf.
-    size_t charsWritten = PR_vsnprintf(buff, kBuffSize, aFmt, aArgs);
+    va_list argsCopy;
+    va_copy(argsCopy, aArgs);
+    size_t charsWritten = PR_vsnprintf(buff, kBuffSize, aFmt, argsCopy);
+    va_end(argsCopy);
+
     if (charsWritten == kBuffSize - 1) {
       // We may have maxed out, allocate a buffer instead.
       buffToWrite = PR_vsmprintf(aFmt, aArgs);
       charsWritten = strlen(buffToWrite);
     }
 
     // Determine if a newline needs to be appended to the message.
     const char* newline = "";