Bug 965022 - Use MOZ_FORMAT_PRINTF for nsTString::AppendPrintf, and fix incorrect usages. r=jrmuizel
☠☠ backed out by 894b7372561d ☠ ☠
authorBotond Ballo <botond@mozilla.com>
Tue, 26 Aug 2014 12:05:41 -0400
changeset 223361 7f68752ffe1e6990b04dccf1b05e87df493adbad
parent 223360 24251d4da0191cc8121b9c693c17aaf35701e717
child 223362 963b26a1a6fbd20a4048a32b714c1c942c69412a
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs965022
milestone34.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 965022 - Use MOZ_FORMAT_PRINTF for nsTString::AppendPrintf, and fix incorrect usages. r=jrmuizel
dom/base/nsWindowMemoryReporter.cpp
dom/canvas/WebGLProgram.cpp
layout/generic/nsFrameState.cpp
layout/style/nsStyleUtil.cpp
netwerk/protocol/http/ConnectionDiagnostics.cpp
xpcom/string/nsTSubstring.h
--- a/dom/base/nsWindowMemoryReporter.cpp
+++ b/dom/base/nsWindowMemoryReporter.cpp
@@ -14,16 +14,17 @@
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "mozilla/StaticPtr.h"
 #include "nsNetCID.h"
 #include "nsPrintfCString.h"
 #include "XPCJSMemoryReporter.h"
 #include "js/MemoryMetrics.h"
 #include "nsServiceManagerUtils.h"
+#include "mozilla/IntegerPrintfMacros.h"
 
 using namespace mozilla;
 
 StaticRefPtr<nsWindowMemoryReporter> sWindowReporter;
 
 /**
  * Don't trigger a ghost window check when a DOM window is detached if we've
  * run it this recently.
@@ -164,17 +165,17 @@ GetWindowURI(nsIDOMWindow *aWindow)
 
 static void
 AppendWindowURI(nsGlobalWindow *aWindow, nsACString& aStr, bool aAnonymize)
 {
   nsCOMPtr<nsIURI> uri = GetWindowURI(aWindow);
 
   if (uri) {
     if (aAnonymize && !aWindow->IsChromeWindow()) {
-      aStr.AppendPrintf("<anonymized-%d>", aWindow->WindowID());
+      aStr.AppendPrintf("<anonymized-%" PRIu64 ">", aWindow->WindowID());
     } else {
       nsCString spec;
       uri->GetSpec(spec);
 
       // A hack: replace forward slashes with '\\' so they aren't
       // treated as path separators.  Users of the reporters
       // (such as about:memory) have to undo this change.
       spec.ReplaceChar('/', '\\');
--- a/dom/canvas/WebGLProgram.cpp
+++ b/dom/canvas/WebGLProgram.cpp
@@ -3,16 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGLContext.h"
 #include "WebGLShader.h"
 #include "WebGLProgram.h"
 #include "mozilla/dom/WebGLRenderingContextBinding.h"
 #include "GLContext.h"
+#include "mozilla/IntegerPrintfMacros.h"
 
 #include "MurmurHash3.h"
 
 using namespace mozilla;
 
 /** Takes an ASCII string like "foo[i]", turns it into "foo" and returns "[i]" in bracketPart
   * 
   * \param string input/output: the string to split, becomes the string without the bracket part
@@ -229,15 +230,15 @@ WebGLProgram::IdentifierHashFunction(con
 }
 
 /* static */ void
 WebGLProgram::HashMapIdentifier(const nsACString& name, nsCString *hashedName)
 {
     uint64_t hash = IdentifierHashFunction(name.BeginReading(), name.Length());
     hashedName->Truncate();
     // This MUST MATCH angle/src/compiler/translator/HashNames.h HASHED_NAME_PREFIX
-    hashedName->AppendPrintf("webgl_%llx", hash);
+    hashedName->AppendPrintf("webgl_%" PRIx64, hash);
 }
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WebGLProgram, mAttachedShaders)
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLProgram, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLProgram, Release)
--- a/layout/generic/nsFrameState.cpp
+++ b/layout/generic/nsFrameState.cpp
@@ -17,16 +17,17 @@
 #include "nsImageFrame.h"
 #include "nsInlineFrame.h"
 #include "nsPlaceholderFrame.h"
 #include "nsSVGContainerFrame.h"
 #include "nsTableCellFrame.h"
 #include "nsTableRowFrame.h"
 #include "nsTableRowGroupFrame.h"
 #include "nsTextFrame.h"
+#include "mozilla/IntegerPrintfMacros.h"
 
 namespace mozilla {
 
 #ifdef DEBUG
 nsCString
 GetFrameState(nsIFrame* aFrame)
 {
   nsCString result;
@@ -54,17 +55,17 @@ GetFrameState(nsIFrame* aFrame)
     result.Insert(#name_, 0);                                                 \
     state = state & ~NS_FRAME_STATE_BIT(value_);                              \
   }
 #include "nsFrameStateBits.h"
 #undef FRAME_STATE_GROUP
 #undef FRAME_STATE_BIT
 
   if (state) {
-    result.AppendPrintf(" | 0x%0llx", state);
+    result.AppendPrintf(" | 0x%0" PRIx64, state);
   }
 
   return result;
 }
 
 void
 PrintFrameState(nsIFrame* aFrame)
 {
--- a/layout/style/nsStyleUtil.cpp
+++ b/layout/style/nsStyleUtil.cpp
@@ -57,17 +57,17 @@ void nsStyleUtil::AppendEscapedCSSString
                   "CSS strings must be quoted with ' or \"");
   aReturn.Append(quoteChar);
 
   const char16_t* in = aString.BeginReading();
   const char16_t* const end = aString.EndReading();
   for (; in != end; in++) {
     if (*in < 0x20 || (*in >= 0x7F && *in < 0xA0)) {
       // Escape U+0000 through U+001F and U+007F through U+009F numerically.
-      aReturn.AppendPrintf("\\%hX ", *in);
+      aReturn.AppendPrintf("\\%hX ", static_cast<int16_t>(*in));
     } else {
       if (*in == '"' || *in == '\'' || *in == '\\') {
         // Escape backslash and quote characters symbolically.
         // It's not technically necessary to escape the quote
         // character that isn't being used to delimit the string,
         // but we do it anyway because that makes testing simpler.
         aReturn.Append(char16_t('\\'));
       }
@@ -111,28 +111,28 @@ nsStyleUtil::AppendEscapedCSSIdent(const
     aReturn.Append(char16_t('-'));
     ++in;
   }
 
   // Escape a digit at the start (including after a dash),
   // numerically.  If we didn't escape it numerically, it would get
   // interpreted as a numeric escape for the wrong character.
   if (in != end && ('0' <= *in && *in <= '9')) {
-    aReturn.AppendPrintf("\\%hX ", *in);
+    aReturn.AppendPrintf("\\%hX ", static_cast<int16_t>(*in));
     ++in;
   }
 
   for (; in != end; ++in) {
     char16_t ch = *in;
     if (ch == 0x00) {
       return false;
     }
     if (ch < 0x20 || (0x7F <= ch && ch < 0xA0)) {
       // Escape U+0000 through U+001F and U+007F through U+009F numerically.
-      aReturn.AppendPrintf("\\%hX ", *in);
+      aReturn.AppendPrintf("\\%hX ", static_cast<int16_t>(*in));
     } else {
       // Escape ASCII non-identifier printables as a backslash plus
       // the character.
       if (ch < 0x7F &&
           ch != '_' && ch != '-' &&
           (ch < '0' || '9' < ch) &&
           (ch < 'A' || 'Z' < ch) &&
           (ch < 'a' || 'z' < ch)) {
--- a/netwerk/protocol/http/ConnectionDiagnostics.cpp
+++ b/netwerk/protocol/http/ConnectionDiagnostics.cpp
@@ -10,16 +10,17 @@
 #include "nsHttpConnectionMgr.h"
 #include "nsHttpConnection.h"
 #include "SpdySession3.h"
 #include "SpdySession31.h"
 #include "Http2Session.h"
 #include "nsHttpHandler.h"
 #include "nsIConsoleService.h"
 #include "nsHttpRequestHead.h"
+#include "mozilla/IntegerPrintfMacros.h"
 
 extern PRThread *gSocketThread;
 
 namespace mozilla {
 namespace net {
 
 void
 nsHttpConnectionMgr::PrintDiagnostics()
@@ -58,23 +59,23 @@ nsHttpConnectionMgr::PrintDiagnosticsCB(
   uint32_t i;
 
   self->mLogData.AppendPrintf(" ent host = %s hashkey = %s\n",
                               ent->mConnInfo->Host(), ent->mConnInfo->HashKey().get());
   self->mLogData.AppendPrintf("   AtActiveConnectionLimit = %d\n",
                               self->AtActiveConnectionLimit(ent, NS_HTTP_ALLOW_KEEPALIVE));
   self->mLogData.AppendPrintf("   RestrictConnections = %d\n",
                               self->RestrictConnections(ent));
-  self->mLogData.AppendPrintf("   Pending Q Length = %u\n",
+  self->mLogData.AppendPrintf("   Pending Q Length = %" PRIuSIZE "\n",
                               ent->mPendingQ.Length());
-  self->mLogData.AppendPrintf("   Active Conns Length = %u\n",
+  self->mLogData.AppendPrintf("   Active Conns Length = %" PRIuSIZE "\n",
                               ent->mActiveConns.Length());
-  self->mLogData.AppendPrintf("   Idle Conns Length = %u\n",
+  self->mLogData.AppendPrintf("   Idle Conns Length = %" PRIuSIZE "\n",
                               ent->mIdleConns.Length());
-  self->mLogData.AppendPrintf("   Half Opens Length = %u\n",
+  self->mLogData.AppendPrintf("   Half Opens Length = %" PRIuSIZE "\n",
                               ent->mHalfOpens.Length());
   self->mLogData.AppendPrintf("   Coalescing Key = %s\n",
                               ent->mCoalescingKey.get());
   self->mLogData.AppendPrintf("   Spdy using = %d, tested = %d, preferred = %d\n",
                               ent->mUsingSpdy, ent->mTestedSpdy, ent->mSpdyPreferred);
   self->mLogData.AppendPrintf("   pipelinestate = %d penalty = %d\n",
                               ent->mPipelineState, ent->mPipeliningPenalty);
   for (i = 0; i < nsAHttpTransaction::CLASS_MAX; ++i) {
@@ -141,17 +142,17 @@ nsHttpConnection::PrintDiagnostics(nsCSt
 
   log.AppendPrintf("    mTransaction = %d mSpdySession = %d\n",
                    !!mTransaction.get(), !!mSpdySession.get());
 
   PRIntervalTime now = PR_IntervalNow();
   log.AppendPrintf("    time since last read = %ums\n",
                    PR_IntervalToMilliseconds(now - mLastReadTime));
 
-  log.AppendPrintf("    max-read/read/written %lld/%lld/%lld\n",
+  log.AppendPrintf("    max-read/read/written %" PRId64 "/%" PRId64 "/%" PRId64 "\n",
                    mMaxBytesRead, mTotalBytesRead, mTotalBytesWritten);
 
   log.AppendPrintf("    rtt = %ums\n", PR_IntervalToMilliseconds(mRtt));
 
   log.AppendPrintf("    idlemonitoring = %d transactionCount=%d\n",
                    mIdleMonitoring, mHttp1xTransactionCount);
 
   log.AppendPrintf("    supports pipeline = %d classification = 0x%x\n",
--- a/xpcom/string/nsTSubstring.h
+++ b/xpcom/string/nsTSubstring.h
@@ -2,16 +2,17 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 // IWYU pragma: private, include "nsString.h"
 
 #include "mozilla/Casting.h"
 #include "mozilla/MemoryReporting.h"
+#include "mozilla/IntegerPrintfMacros.h"
 
 #ifndef MOZILLA_INTERNAL_API
 #error Cannot use internal string classes without MOZILLA_INTERNAL_API defined. Use the frozen header nsStringAPI.h instead.
 #endif
 
 /**
  * The base for string comparators
  */
@@ -551,17 +552,18 @@ public:
   {
     ReplaceASCII(mLength, 0, aData, aLength);
   }
 
   /**
    * Append a formatted string to the current string. Uses the format
    * codes documented in prprf.h
    */
-  void AppendPrintf(const char* aFormat, ...);
+  // Note: MOZ_FORMAT_PRINTF(2, 3) because 'this counts as a parameter.
+  void AppendPrintf(const char* aFormat, ...) MOZ_FORMAT_PRINTF(2, 3);
   void AppendPrintf(const char* aFormat, va_list aAp);
   void AppendInt(int32_t aInteger)
   {
     AppendPrintf("%d", aInteger);
   }
   void AppendInt(int32_t aInteger, int aRadix)
   {
     const char* fmt = aRadix == 10 ? "%d" : aRadix == 8 ? "%o" : "%x";
@@ -573,30 +575,30 @@ public:
   }
   void AppendInt(uint32_t aInteger, int aRadix)
   {
     const char* fmt = aRadix == 10 ? "%u" : aRadix == 8 ? "%o" : "%x";
     AppendPrintf(fmt, aInteger);
   }
   void AppendInt(int64_t aInteger)
   {
-    AppendPrintf("%lld", aInteger);
+    AppendPrintf("%" PRId64, aInteger);
   }
   void AppendInt(int64_t aInteger, int aRadix)
   {
-    const char* fmt = aRadix == 10 ? "%lld" : aRadix == 8 ? "%llo" : "%llx";
+    const char* fmt = aRadix == 10 ? "%" PRId64 : aRadix == 8 ? "%" PRIo64 : "%" PRIx64;
     AppendPrintf(fmt, aInteger);
   }
   void AppendInt(uint64_t aInteger)
   {
-    AppendPrintf("%llu", aInteger);
+    AppendPrintf("%" PRIu64, aInteger);
   }
   void AppendInt(uint64_t aInteger, int aRadix)
   {
-    const char* fmt = aRadix == 10 ? "%llu" : aRadix == 8 ? "%llo" : "%llx";
+    const char* fmt = aRadix == 10 ? "%" PRIu64 : aRadix == 8 ? "%" PRIo64 : "%" PRIx64;
     AppendPrintf(fmt, aInteger);
   }
 
   /**
    * Append the given float to this string
    */
   void NS_FASTCALL AppendFloat(float aFloat);
   void NS_FASTCALL AppendFloat(double aFloat);