Bug 915765 - fix -Wformat warnings in xpcom/; r=bsmedberg
authorNathan Froyd <froydnj@mozilla.com>
Thu, 12 Sep 2013 13:18:36 -0400
changeset 162280 c7e4cab76ab8ae4ff5ac09e173b731ff62085f25
parent 162279 b5d45a95d4ba33fc8d301ffd9a6720cbbce88c8a
child 162281 6aa2044de89d600daa822f516151ac7e303786b5
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs915765
milestone27.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 915765 - fix -Wformat warnings in xpcom/; r=bsmedberg Unfortunately this doesn't fix all platforms, since Android's inttypes.h doesn't have the right macros for intptr_t at least, but it makes the situation a little better.
xpcom/base/nsStackWalk.cpp
xpcom/base/nsTraceRefcntImpl.cpp
--- a/xpcom/base/nsStackWalk.cpp
+++ b/xpcom/base/nsStackWalk.cpp
@@ -1,18 +1,19 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
 /* 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/. */
 
 /* API for getting a stack trace of the C/C++ stack on the current thread */
 
+#include "mozilla/Assertions.h"
+#include "mozilla/IntegerPrintfMacros.h"
 #include "mozilla/StackWalk.h"
-#include "mozilla/Assertions.h"
 #include "nsStackWalkPrivate.h"
 
 #include "nsStackWalk.h"
 
 using namespace mozilla;
 
 // The presence of this address is the stack must stop the stack walk. If
 // there is no such address, the structure will be {NULL, true}.
@@ -1312,20 +1313,21 @@ NS_DescribeCodeAddress(void *aPC, nsCode
 
 EXPORT_XPCOM_API(nsresult)
 NS_FormatCodeAddressDetails(void *aPC, const nsCodeAddressDetails *aDetails,
                             char *aBuffer, uint32_t aBufferSize)
 {
   if (!aDetails->library[0]) {
     snprintf(aBuffer, aBufferSize, "UNKNOWN %p\n", aPC);
   } else if (!aDetails->function[0]) {
-    snprintf(aBuffer, aBufferSize, "UNKNOWN [%s +0x%08lX]\n",
+    snprintf(aBuffer, aBufferSize, "UNKNOWN [%s +0x%08" PRIxPTR "]\n",
                                    aDetails->library, aDetails->loffset);
   } else {
-    snprintf(aBuffer, aBufferSize, "%s+0x%08lX [%s +0x%08lX]\n",
+    snprintf(aBuffer, aBufferSize, "%s+0x%08" PRIxPTR
+                                   " [%s +0x%08" PRIxPTR "]\n",
                                    aDetails->function, aDetails->foffset,
                                    aDetails->library, aDetails->loffset);
   }
   return NS_OK;
 }
 
 #endif
 
--- a/xpcom/base/nsTraceRefcntImpl.cpp
+++ b/xpcom/base/nsTraceRefcntImpl.cpp
@@ -1,14 +1,15 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/. */
 
 #include "nsTraceRefcntImpl.h"
+#include "mozilla/IntegerPrintfMacros.h"
 #include "nsXPCOMPrivate.h"
 #include "nscore.h"
 #include "nsISupports.h"
 #include "nsTArray.h"
 #include "prenv.h"
 #include "plstr.h"
 #include "prlink.h"
 #include "nsCRT.h"
@@ -358,17 +359,17 @@ public:
     if ((stats->mAddRefs - stats->mReleases) != 0 ||
         stats->mAddRefs != 0 ||
         meanRefs != 0 ||
         stddevRefs != 0 ||
         (stats->mCreates - stats->mDestroys) != 0 ||
         stats->mCreates != 0 ||
         meanObjs != 0 ||
         stddevObjs != 0) {
-      fprintf(out, "%4d %-40.40s %8d %8llu %8llu %8llu (%8.2f +/- %8.2f) %8llu %8llu (%8.2f +/- %8.2f)\n",
+      fprintf(out, "%4d %-40.40s %8d %8" PRIu64 " %8" PRIu64 " %8" PRIu64 " (%8.2f +/- %8.2f) %8" PRIu64 " %8" PRIu64 " (%8.2f +/- %8.2f)\n",
               i+1, mClassName,
               (int32_t)mClassSize,
               (nsCRT::strcmp(mClassName, "TOTAL"))
                   ?(uint64_t)((stats->mCreates - stats->mDestroys) * mClassSize)
                   :mTotalLeaked,
               stats->mCreates,
               (stats->mCreates - stats->mDestroys),
               meanObjs,
@@ -438,23 +439,25 @@ GetBloatEntry(const char* aTypeName, uin
   }
   return entry;
 }
 
 static int DumpSerialNumbers(PLHashEntry* aHashEntry, int aIndex, void* aClosure)
 {
   serialNumberRecord* record = reinterpret_cast<serialNumberRecord *>(aHashEntry->value);
 #ifdef HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR
-  fprintf((FILE*) aClosure, "%ld @%p (%d references; %d from COMPtrs)\n",
+  fprintf((FILE*) aClosure, "%" PRIdPTR
+                            " @%p (%d references; %d from COMPtrs)\n",
                             record->serialNumber,
                             NS_INT32_TO_PTR(aHashEntry->key),
                             record->refCount,
                             record->COMPtrCount);
 #else
-  fprintf((FILE*) aClosure, "%ld @%p (%d references)\n",
+  fprintf((FILE*) aClosure, "%" PRIdPTR
+                            " @%p (%d references)\n",
                             record->serialNumber,
                             NS_INT32_TO_PTR(aHashEntry->key),
                             record->refCount);
 #endif
   return HT_ENUMERATE_NEXT;
 }
 
 
@@ -806,17 +809,17 @@ static void InitTraceLog(void)
           top += *cp - '0';
           ++cp;
         }
         if (!bottom) {
           bottom = top;
         }
         for (intptr_t serialno = bottom; serialno <= top; serialno++) {
           PL_HashTableAdd(gObjectsToLog, (const void*)serialno, (void*)1);
-          fprintf(stdout, "%ld ", serialno);
+          fprintf(stdout, "%" PRIdPTR " ", serialno);
         }
         if (!cm) break;
         *cm = ',';
         cp = cm + 1;
       }
       fprintf(stdout, "\n");
     }
   }
@@ -981,29 +984,29 @@ NS_LogAddRef(void* aPtr, nsrefcnt aRefcn
       int32_t* count = GetRefCount(aPtr);
       if(count)
         (*count)++;
 
     }
 
     bool loggingThisObject = (!gObjectsToLog || LogThisObj(serialno));
     if (aRefcnt == 1 && gAllocLog && loggingThisType && loggingThisObject) {
-      fprintf(gAllocLog, "\n<%s> 0x%08X %ld Create\n",
+      fprintf(gAllocLog, "\n<%s> 0x%08X %" PRIdPTR " Create\n",
               aClazz, NS_PTR_TO_INT32(aPtr), serialno);
       nsTraceRefcntImpl::WalkTheStack(gAllocLog);
     }
 
     if (gRefcntsLog && loggingThisType && loggingThisObject) {
       if (gLogToLeaky) {
         (*leakyLogAddRef)(aPtr, aRefcnt - 1, aRefcnt);
       }
       else {
           // Can't use PR_LOG(), b/c it truncates the line
           fprintf(gRefcntsLog,
-                  "\n<%s> 0x%08X %ld AddRef %d\n", aClazz, NS_PTR_TO_INT32(aPtr), serialno, aRefcnt);
+                  "\n<%s> 0x%08X %" PRIdPTR " AddRef %d\n", aClazz, NS_PTR_TO_INT32(aPtr), serialno, aRefcnt);
           nsTraceRefcntImpl::WalkTheStack(gRefcntsLog);
           fflush(gRefcntsLog);
       }
     }
     UNLOCK_TRACELOG();
   }
 #endif
 }
@@ -1041,28 +1044,28 @@ NS_LogRelease(void* aPtr, nsrefcnt aRefc
     bool loggingThisObject = (!gObjectsToLog || LogThisObj(serialno));
     if (gRefcntsLog && loggingThisType && loggingThisObject) {
       if (gLogToLeaky) {
         (*leakyLogRelease)(aPtr, aRefcnt + 1, aRefcnt);
       }
       else {
           // Can't use PR_LOG(), b/c it truncates the line
           fprintf(gRefcntsLog,
-                  "\n<%s> 0x%08X %ld Release %d\n", aClazz, NS_PTR_TO_INT32(aPtr), serialno, aRefcnt);
+                  "\n<%s> 0x%08X %" PRIdPTR " Release %d\n", aClazz, NS_PTR_TO_INT32(aPtr), serialno, aRefcnt);
           nsTraceRefcntImpl::WalkTheStack(gRefcntsLog);
           fflush(gRefcntsLog);
       }
     }
 
     // Here's the case where MOZ_COUNT_DTOR was not used,
     // yet we still want to see deletion information:
 
     if (aRefcnt == 0 && gAllocLog && loggingThisType && loggingThisObject) {
       fprintf(gAllocLog,
-              "\n<%s> 0x%08X %ld Destroy\n",
+              "\n<%s> 0x%08X %" PRIdPTR " Destroy\n",
               aClazz, NS_PTR_TO_INT32(aPtr), serialno);
       nsTraceRefcntImpl::WalkTheStack(gAllocLog);
     }
 
     if (aRefcnt == 0 && gSerialNumbers && loggingThisType) {
       RecycleSerialNumberPtr(aPtr);
     }
 
@@ -1092,17 +1095,17 @@ NS_LogCtor(void* aPtr, const char* aType
     bool loggingThisType = (!gTypesToLog || LogThisType(aType));
     intptr_t serialno = 0;
     if (gSerialNumbers && loggingThisType) {
       serialno = GetSerialNumber(aPtr, true);
     }
 
     bool loggingThisObject = (!gObjectsToLog || LogThisObj(serialno));
     if (gAllocLog && loggingThisType && loggingThisObject) {
-      fprintf(gAllocLog, "\n<%s> 0x%08X %ld Ctor (%d)\n",
+      fprintf(gAllocLog, "\n<%s> 0x%08X %" PRIdPTR " Ctor (%d)\n",
              aType, NS_PTR_TO_INT32(aPtr), serialno, aInstanceSize);
       nsTraceRefcntImpl::WalkTheStack(gAllocLog);
     }
 
     UNLOCK_TRACELOG();
   }
 #endif
 }
@@ -1133,17 +1136,17 @@ NS_LogDtor(void* aPtr, const char* aType
       RecycleSerialNumberPtr(aPtr);
     }
 
     bool loggingThisObject = (!gObjectsToLog || LogThisObj(serialno));
 
     // (If we're on a losing architecture, don't do this because we'll be
     // using LogDeleteXPCOM instead to get file and line numbers.)
     if (gAllocLog && loggingThisType && loggingThisObject) {
-      fprintf(gAllocLog, "\n<%s> 0x%08X %ld Dtor (%d)\n",
+      fprintf(gAllocLog, "\n<%s> 0x%08X %" PRIdPTR " Dtor (%d)\n",
              aType, NS_PTR_TO_INT32(aPtr), serialno, aInstanceSize);
       nsTraceRefcntImpl::WalkTheStack(gAllocLog);
     }
 
     UNLOCK_TRACELOG();
   }
 #endif
 }
@@ -1174,17 +1177,17 @@ NS_LogCOMPtrAddRef(void* aCOMPtr, nsISup
 
     int32_t* count = GetCOMPtrCount(object);
     if(count)
       (*count)++;
 
     bool loggingThisObject = (!gObjectsToLog || LogThisObj(serialno));
 
     if (gCOMPtrLog && loggingThisObject) {
-      fprintf(gCOMPtrLog, "\n<?> 0x%08X %ld nsCOMPtrAddRef %d 0x%08X\n",
+      fprintf(gCOMPtrLog, "\n<?> 0x%08X %" PRIdPTR " nsCOMPtrAddRef %d 0x%08X\n",
               NS_PTR_TO_INT32(object), serialno, count?(*count):-1, NS_PTR_TO_INT32(aCOMPtr));
       nsTraceRefcntImpl::WalkTheStack(gCOMPtrLog);
     }
 
     UNLOCK_TRACELOG();
   }
 #endif
 }
@@ -1215,17 +1218,17 @@ NS_LogCOMPtrRelease(void* aCOMPtr, nsISu
 
     int32_t* count = GetCOMPtrCount(object);
     if(count)
       (*count)--;
 
     bool loggingThisObject = (!gObjectsToLog || LogThisObj(serialno));
 
     if (gCOMPtrLog && loggingThisObject) {
-      fprintf(gCOMPtrLog, "\n<?> 0x%08X %ld nsCOMPtrRelease %d 0x%08X\n",
+      fprintf(gCOMPtrLog, "\n<?> 0x%08X %" PRIdPTR " nsCOMPtrRelease %d 0x%08X\n",
               NS_PTR_TO_INT32(object), serialno, count?(*count):-1, NS_PTR_TO_INT32(aCOMPtr));
       nsTraceRefcntImpl::WalkTheStack(gCOMPtrLog);
     }
 
     UNLOCK_TRACELOG();
   }
 #endif
 }