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.
This commit is contained in:
Nathan Froyd 2013-09-12 13:18:36 -04:00
parent 852cc698b9
commit 1d18ef8622
2 changed files with 20 additions and 15 deletions

View File

@ -6,8 +6,9 @@
/* API for getting a stack trace of the C/C++ stack on the current thread */
#include "mozilla/StackWalk.h"
#include "mozilla/Assertions.h"
#include "mozilla/IntegerPrintfMacros.h"
#include "mozilla/StackWalk.h"
#include "nsStackWalkPrivate.h"
#include "nsStackWalk.h"
@ -1317,10 +1318,11 @@ NS_FormatCodeAddressDetails(void *aPC, const nsCodeAddressDetails *aDetails,
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);
}

View File

@ -4,6 +4,7 @@
* 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"
@ -363,7 +364,7 @@ public:
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"))
@ -443,13 +444,15 @@ 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);
@ -811,7 +814,7 @@ static void InitTraceLog(void)
}
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 = ',';
@ -986,7 +989,7 @@ NS_LogAddRef(void* aPtr, nsrefcnt aRefcnt,
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);
}
@ -998,7 +1001,7 @@ NS_LogAddRef(void* aPtr, nsrefcnt 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);
}
@ -1046,7 +1049,7 @@ NS_LogRelease(void* aPtr, nsrefcnt aRefcnt, const char* aClazz)
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);
}
@ -1057,7 +1060,7 @@ NS_LogRelease(void* aPtr, nsrefcnt aRefcnt, const char* aClazz)
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);
}
@ -1097,7 +1100,7 @@ NS_LogCtor(void* aPtr, const char* aType, uint32_t aInstanceSize)
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);
}
@ -1138,7 +1141,7 @@ NS_LogDtor(void* aPtr, const char* aType, uint32_t aInstanceSize)
// (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);
}
@ -1179,7 +1182,7 @@ NS_LogCOMPtrAddRef(void* aCOMPtr, nsISupports* aObject)
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);
}
@ -1220,7 +1223,7 @@ NS_LogCOMPtrRelease(void* aCOMPtr, nsISupports* aObject)
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);
}