diff --git a/dom/base/DOMException.cpp b/dom/base/DOMException.cpp index cd54ae95873f..fa7e376d911b 100644 --- a/dom/base/DOMException.cpp +++ b/dom/base/DOMException.cpp @@ -360,7 +360,7 @@ Exception::ToString(JSContext* aCx, nsACString& _retval) static const char defaultMsg[] = ""; static const char defaultLocation[] = ""; static const char format[] = -"[Exception... \"%s\" nsresult: \"0x%x (%s)\" location: \"%s\" data: %s]"; +"[Exception... \"%s\" nsresult: \"0x%" PRIx32 " (%s)\" location: \"%s\" data: %s]"; nsCString location; @@ -388,7 +388,7 @@ Exception::ToString(JSContext* aCx, nsACString& _retval) const char* data = mData ? "yes" : "no"; _retval.Truncate(); - _retval.AppendPrintf(format, msg, mResult, resultName, + _retval.AppendPrintf(format, msg, static_cast(mResult), resultName, location.get(), data); return NS_OK; } @@ -552,7 +552,7 @@ DOMException::ToString(JSContext* aCx, nsACString& aReturn) static const char defaultLocation[] = ""; static const char defaultName[] = ""; static const char format[] = - "[Exception... \"%s\" code: \"%d\" nsresult: \"0x%x (%s)\" location: \"%s\"]"; + "[Exception... \"%s\" code: \"%d\" nsresult: \"0x%" PRIx32 " (%s)\" location: \"%s\"]"; nsAutoCString location; @@ -563,7 +563,7 @@ DOMException::ToString(JSContext* aCx, nsACString& aReturn) const char* msg = !mMessage.IsEmpty() ? mMessage.get() : defaultMsg; const char* resultName = !mName.IsEmpty() ? mName.get() : defaultName; - aReturn.AppendPrintf(format, msg, mCode, mResult, resultName, + aReturn.AppendPrintf(format, msg, mCode, static_cast(mResult), resultName, location.get()); return NS_OK; diff --git a/dom/base/nsWindowMemoryReporter.cpp b/dom/base/nsWindowMemoryReporter.cpp index acbcb109ae6b..dfe615d8e6b3 100644 --- a/dom/base/nsWindowMemoryReporter.cpp +++ b/dom/base/nsWindowMemoryReporter.cpp @@ -168,7 +168,7 @@ AppendWindowURI(nsGlobalWindow *aWindow, nsACString& aStr, bool aAnonymize) if (uri) { if (aAnonymize && !aWindow->IsChromeWindow()) { - aStr.AppendPrintf("", aWindow->WindowID()); + aStr.AppendPrintf("", aWindow->WindowID()); } else { nsCString spec = uri->GetSpecOrDefault(); @@ -276,7 +276,7 @@ CollectWindowReports(nsGlobalWindow *aWindow, if (top) { windowPath += NS_LITERAL_CSTRING("top("); AppendWindowURI(top, windowPath, aAnonymize); - windowPath.AppendPrintf(", id=%llu)", top->WindowID()); + windowPath.AppendPrintf(", id=%" PRIu64 ")", top->WindowID()); aTopWindowPaths->Put(aWindow->WindowID(), windowPath); diff --git a/dom/file/MemoryBlobImpl.cpp b/dom/file/MemoryBlobImpl.cpp index 2cf7cfdd0cad..ea129b53eea8 100644 --- a/dom/file/MemoryBlobImpl.cpp +++ b/dom/file/MemoryBlobImpl.cpp @@ -5,6 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "MemoryBlobImpl.h" +#include "mozilla/IntegerPrintfMacros.h" #include "mozilla/SHA1.h" #include "nsIIPCSerializableInputStream.h" #include "nsPrintfCString.h" @@ -166,11 +167,11 @@ public: aHandleReport->Callback( /* process */ NS_LITERAL_CSTRING(""), nsPrintfCString( - "explicit/dom/memory-file-data/large/file(length=%llu, sha1=%s)", + "explicit/dom/memory-file-data/large/file(length=%" PRIu64 ", sha1=%s)", owner->mLength, aAnonymize ? "" : digestString.get()), KIND_HEAP, UNITS_BYTES, size, nsPrintfCString( - "Memory used to back a memory file of length %llu bytes. The file " + "Memory used to back a memory file of length %" PRIu64 " bytes. The file " "has a sha1 of %s.\n\n" "Note that the allocator may round up a memory file's length -- " "that is, an N-byte memory file may take up more than N bytes of " diff --git a/dom/indexedDB/ActorsParent.cpp b/dom/indexedDB/ActorsParent.cpp index 7aacd9a6492b..fd4c970b7a3b 100644 --- a/dom/indexedDB/ActorsParent.cpp +++ b/dom/indexedDB/ActorsParent.cpp @@ -26,6 +26,7 @@ #include "mozilla/Maybe.h" #include "mozilla/Preferences.h" #include "mozilla/Services.h" +#include "mozilla/SizePrintfMacros.h" #include "mozilla/SnappyCompressOutputStream.h" #include "mozilla/SnappyUncompressInputStream.h" #include "mozilla/StaticPtr.h" @@ -583,9 +584,9 @@ ClampResultCode(nsresult aResultCode) return NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR; default: #ifdef DEBUG - nsPrintfCString message("Converting non-IndexedDB error code (0x%X) to " + nsPrintfCString message("Converting non-IndexedDB error code (0x%" PRIX32 ") to " "NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR", - aResultCode); + static_cast(aResultCode)); NS_WARNING(message.get()); #else ; @@ -4557,7 +4558,7 @@ CreateStorageConnection(nsIFile* aDBFile, // Set the page size first. if (kSQLitePageSizeOverride) { rv = connection->ExecuteSimpleSQL( - nsPrintfCString("PRAGMA page_size = %lu;", kSQLitePageSizeOverride) + nsPrintfCString("PRAGMA page_size = %" PRIu32 ";", kSQLitePageSizeOverride) ); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; @@ -4793,7 +4794,7 @@ CreateStorageConnection(nsIFile* aDBFile, // Successfully set to rollback journal mode so changing the page size // is possible with a VACUUM. rv = connection->ExecuteSimpleSQL( - nsPrintfCString("PRAGMA page_size = %lu;", kSQLitePageSizeOverride) + nsPrintfCString("PRAGMA page_size = %" PRIu32 ";", kSQLitePageSizeOverride) ); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; @@ -5724,7 +5725,7 @@ public: nsCString GetThreadName() const { - return nsPrintfCString("IndexedDB #%lu", mSerialNumber); + return nsPrintfCString("IndexedDB #%" PRIu32, mSerialNumber); } private: diff --git a/dom/indexedDB/ProfilerHelpers.h b/dom/indexedDB/ProfilerHelpers.h index 63fdafcceb76..aec65c4e75b1 100644 --- a/dom/indexedDB/ProfilerHelpers.h +++ b/dom/indexedDB/ProfilerHelpers.h @@ -277,7 +277,7 @@ public: } }; -inline void +inline void MOZ_FORMAT_PRINTF(2, 3) LoggingHelper(bool aUseProfiler, const char* aFmt, ...) { MOZ_ASSERT(IndexedDatabaseManager::GetLoggingMode() != diff --git a/dom/indexedDB/ReportInternalError.cpp b/dom/indexedDB/ReportInternalError.cpp index 267b84a76bd4..b86071b29a66 100644 --- a/dom/indexedDB/ReportInternalError.cpp +++ b/dom/indexedDB/ReportInternalError.cpp @@ -27,7 +27,7 @@ ReportInternalError(const char* aFile, uint32_t aLine, const char* aStr) nsContentUtils::LogSimpleConsoleError( NS_ConvertUTF8toUTF16(nsPrintfCString( - "IndexedDB %s: %s:%lu", aStr, aFile, aLine)), + "IndexedDB %s: %s:%" PRIu32, aStr, aFile, aLine)), "indexedDB"); } diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 0a669a59d84d..c998ef088f6d 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -419,7 +419,7 @@ ContentParentsMemoryReporter::CollectReports( } nsPrintfCString path("queued-ipc-messages/content-parent" - "(%s, pid=%d, %s, 0x%p, refcnt=%d)", + "(%s, pid=%d, %s, 0x%p, refcnt=%" PRIuPTR ")", NS_ConvertUTF16toUTF8(friendlyName).get(), cp->Pid(), channelStr, static_cast(cp), refcnt); diff --git a/dom/ipc/ProcessPriorityManager.cpp b/dom/ipc/ProcessPriorityManager.cpp index 75e2e0065144..d5ee327de495 100644 --- a/dom/ipc/ProcessPriorityManager.cpp +++ b/dom/ipc/ProcessPriorityManager.cpp @@ -534,7 +534,7 @@ ProcessPriorityManagerImpl::GetParticularProcessPriorityManager( mParticularManagers.Put(cpId, pppm); FireTestOnlyObserverNotification("process-created", - nsPrintfCString("%lld", cpId)); + nsPrintfCString("%" PRIu64, cpId)); } return pppm.forget(); @@ -1195,7 +1195,7 @@ ParticularProcessPriorityManager::FireTestOnlyObserverNotification( return; } - nsAutoCString data(nsPrintfCString("%lld", ChildID())); + nsAutoCString data(nsPrintfCString("%" PRIu64, ChildID())); if (!aData.IsEmpty()) { data.Append(':'); data.Append(aData); diff --git a/dom/media/DecoderDoctorDiagnostics.cpp b/dom/media/DecoderDoctorDiagnostics.cpp index 86450e853f2b..620f9ac297ef 100644 --- a/dom/media/DecoderDoctorDiagnostics.cpp +++ b/dom/media/DecoderDoctorDiagnostics.cpp @@ -834,8 +834,8 @@ DecoderDoctorDiagnostics::GetDescription() const } break; case eEvent: - s = nsPrintfCString("event domain %s result=%u", - EventDomainString(mEvent.mDomain), mEvent.mResult); + s = nsPrintfCString("event domain %s result=%" PRIu32, + EventDomainString(mEvent.mDomain), static_cast(mEvent.mResult)); break; default: MOZ_ASSERT_UNREACHABLE("Unexpected DiagnosticsType"); diff --git a/dom/media/MediaDecoderReader.cpp b/dom/media/MediaDecoderReader.cpp index f39b693f635e..4cafa569f705 100644 --- a/dom/media/MediaDecoderReader.cpp +++ b/dom/media/MediaDecoderReader.cpp @@ -225,7 +225,8 @@ MediaDecoderReader::AsyncReadMetadata() // We're not waiting for anything. If we didn't get the metadata, that's an // error. if (NS_FAILED(rv) || !metadata->mInfo.HasValidMedia()) { - DECODER_WARN("ReadMetadata failed, rv=%x HasValidMedia=%d", rv, metadata->mInfo.HasValidMedia()); + DECODER_WARN("ReadMetadata failed, rv=%" PRIx32 " HasValidMedia=%d", + static_cast(rv), metadata->mInfo.HasValidMedia()); return MetadataPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_METADATA_ERR, __func__); } diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index b93e25f776fb..58a2d3a3aca1 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -3756,11 +3756,11 @@ MediaDecoderStateMachine::GetDebugInfo() { MOZ_ASSERT(OnTaskQueue()); return nsPrintfCString( - "GetMediaTime=%lld GetClock=%lld mMediaSink=%p " + "GetMediaTime=%" PRId64 " GetClock=%" PRId64 " mMediaSink=%p " "state=%s mPlayState=%d mSentFirstFrameLoadedEvent=%d IsPlaying=%d " - "mAudioStatus=%s mVideoStatus=%s mDecodedAudioEndTime=%lld " - "mDecodedVideoEndTime=%lld " - "mAudioCompleted=%d mVideoCompleted=%d ", + "mAudioStatus=%s mVideoStatus=%s mDecodedAudioEndTime=%" PRId64 + " mDecodedVideoEndTime=%" PRId64 + " mAudioCompleted=%d mVideoCompleted=%d ", GetMediaTime(), mMediaSink->IsStarted() ? GetClock() : -1, mMediaSink.get(), ToStateStr(), mPlayState.Ref(), mSentFirstFrameLoadedEvent, IsPlaying(), AudioRequestStatus(), diff --git a/dom/media/MediaFormatReader.cpp b/dom/media/MediaFormatReader.cpp index 0fe585023292..5ae622e505cc 100644 --- a/dom/media/MediaFormatReader.cpp +++ b/dom/media/MediaFormatReader.cpp @@ -2786,12 +2786,12 @@ MediaFormatReader::GetMozDebugReaderData(nsACString& aString) } result += nsPrintfCString("audio decoder: %s\n", audioName); - result += nsPrintfCString("audio frames decoded: %lld\n", + result += nsPrintfCString("audio frames decoded: %" PRIu64 "\n", mAudio.mNumSamplesOutputTotal); if (HasAudio()) { result += nsPrintfCString( - "audio state: ni=%d no=%d demuxr:%d demuxq:%d tt:%f tths:%d in:%llu " - "out:%llu qs=%u pending:%u waiting:%d sid:%u\n", + "audio state: ni=%d no=%d demuxr:%d demuxq:%d tt:%f tths:%d in:%" PRIu64 + " out:%" PRIu64 " qs=%u pending:%u waiting:%d sid:%u\n", NeedInput(mAudio), mAudio.HasPromise(), mAudio.mDemuxRequest.Exists(), int(mAudio.mQueuedSamples.Length()), mAudio.mTimeThreshold ? mAudio.mTimeThreshold.ref().Time().ToSeconds() @@ -2805,13 +2805,13 @@ MediaFormatReader::GetMozDebugReaderData(nsACString& aString) result += nsPrintfCString("hardware video decoding: %s\n", VideoIsHardwareAccelerated() ? "enabled" : "disabled"); - result += nsPrintfCString("video frames decoded: %lld (skipped:%lld)\n", + result += nsPrintfCString("video frames decoded: %" PRIu64 " (skipped:%" PRIu64 ")\n", mVideo.mNumSamplesOutputTotal, mVideo.mNumSamplesSkippedTotal); if (HasVideo()) { result += nsPrintfCString( - "video state: ni=%d no=%d demuxr:%d demuxq:%d tt:%f tths:%d in:%llu " - "out:%llu qs=%u pending:%u waiting:%d sid:%u\n", + "video state: ni=%d no=%d demuxr:%d demuxq:%d tt:%f tths:%d in:%" PRIu64 + " out:%" PRIu64 " qs=%u pending:%u waiting:%d sid:%u\n", NeedInput(mVideo), mVideo.HasPromise(), mVideo.mDemuxRequest.Exists(), int(mVideo.mQueuedSamples.Length()), mVideo.mTimeThreshold ? mVideo.mTimeThreshold.ref().Time().ToSeconds() diff --git a/dom/media/MediaResult.h b/dom/media/MediaResult.h index c1e0af64c90e..bf00dae44acc 100644 --- a/dom/media/MediaResult.h +++ b/dom/media/MediaResult.h @@ -51,7 +51,7 @@ public: if (NS_SUCCEEDED(mCode)) { return nsCString(); } - return nsPrintfCString("0x%08x: %s", mCode, mMessage.get()); + return nsPrintfCString("0x%08" PRIx32 ": %s", static_cast(mCode), mMessage.get()); } private: @@ -62,4 +62,4 @@ private: #define RESULT_DETAIL(arg, ...) nsPrintfCString("%s: " arg, __func__, ##__VA_ARGS__) } // namespace mozilla -#endif // MediaResult_h_ \ No newline at end of file +#endif // MediaResult_h_ diff --git a/dom/media/eme/DetailedPromise.cpp b/dom/media/eme/DetailedPromise.cpp index 0acab4e95892..5d7d25083f22 100644 --- a/dom/media/eme/DetailedPromise.cpp +++ b/dom/media/eme/DetailedPromise.cpp @@ -42,8 +42,8 @@ DetailedPromise::~DetailedPromise() void DetailedPromise::MaybeReject(nsresult aArg, const nsACString& aReason) { - nsPrintfCString msg("%s promise rejected 0x%x '%s'", mName.get(), aArg, - PromiseFlatCString(aReason).get()); + nsPrintfCString msg("%s promise rejected 0x%" PRIx32 " '%s'", mName.get(), + static_cast(aArg), PromiseFlatCString(aReason).get()); EME_LOG("%s", msg.get()); MaybeReportTelemetry(Failed); diff --git a/dom/media/fmp4/MP4Demuxer.cpp b/dom/media/fmp4/MP4Demuxer.cpp index 52a892464c22..1828eae8f851 100644 --- a/dom/media/fmp4/MP4Demuxer.cpp +++ b/dom/media/fmp4/MP4Demuxer.cpp @@ -341,7 +341,8 @@ MP4TrackDemuxer::GetNextSample() bool keyframe = type == mp4_demuxer::H264::FrameType::I_FRAME; if (sample->mKeyframe != keyframe) { NS_WARNING(nsPrintfCString("Frame incorrectly marked as %skeyframe " - "@ pts:%lld dur:%u dts:%lld", + "@ pts:%" PRId64 " dur:%" PRId64 + " dts:%" PRId64, keyframe ? "" : "non-", sample->mTime, sample->mDuration, sample->mTimecode) .get()); @@ -351,7 +352,8 @@ MP4TrackDemuxer::GetNextSample() } case mp4_demuxer::H264::FrameType::INVALID: NS_WARNING( - nsPrintfCString("Invalid H264 frame @ pts:%lld dur:%u dts:%lld", + nsPrintfCString("Invalid H264 frame @ pts:%" PRId64 " dur:%" PRId64 + " dts:%" PRId64, sample->mTime, sample->mDuration, sample->mTimecode) .get()); // We could reject the sample now, however demuxer errors are fatal. diff --git a/dom/media/mediasink/DecodedStream.cpp b/dom/media/mediasink/DecodedStream.cpp index 56ac820a1282..921f6d4e6951 100644 --- a/dom/media/mediasink/DecodedStream.cpp +++ b/dom/media/mediasink/DecodedStream.cpp @@ -230,8 +230,8 @@ nsCString DecodedStreamData::GetDebugInfo() { return nsPrintfCString( - "DecodedStreamData=%p mPlaying=%d mAudioFramesWritten=%lld " - "mNextAudioTime=%lld mNextVideoTime=%lld mHaveSentFinish=%d " + "DecodedStreamData=%p mPlaying=%d mAudioFramesWritten=%" PRId64 + " mNextAudioTime=%" PRId64 " mNextVideoTime=%" PRId64 " mHaveSentFinish=%d " "mHaveSentFinishAudio=%d mHaveSentFinishVideo=%d", this, mPlaying, mAudioFramesWritten, mNextAudioTime, mNextVideoTime, mHaveSentFinish, mHaveSentFinishAudio, mHaveSentFinishVideo); @@ -781,7 +781,7 @@ DecodedStream::GetDebugInfo() { AssertOwnerThread(); return nsPrintfCString( - "DecodedStream=%p mStartTime=%lld mLastOutputTime=%lld mPlaying=%d mData=%p", + "DecodedStream=%p mStartTime=%" PRId64 " mLastOutputTime=%" PRId64 " mPlaying=%d mData=%p", this, mStartTime.valueOr(-1), mLastOutputTime, mPlaying, mData.get()) + (mData ? nsCString("\n") + mData->GetDebugInfo() : nsCString()); } diff --git a/dom/media/mediasink/VideoSink.cpp b/dom/media/mediasink/VideoSink.cpp index 1fca89280c0f..b0f82c8132d4 100644 --- a/dom/media/mediasink/VideoSink.cpp +++ b/dom/media/mediasink/VideoSink.cpp @@ -479,8 +479,8 @@ VideoSink::GetDebugInfo() { AssertOwnerThread(); return nsPrintfCString( - "IsStarted=%d IsPlaying=%d, VideoQueue: finished=%d size=%d, " - "mVideoFrameEndTime=%lld mHasVideo=%d mVideoSinkEndRequest.Exists()=%d " + "IsStarted=%d IsPlaying=%d, VideoQueue: finished=%d size=%" PRIuSIZE ", " + "mVideoFrameEndTime=%" PRId64 " mHasVideo=%d mVideoSinkEndRequest.Exists()=%d " "mEndPromiseHolder.IsEmpty()=%d\n", IsStarted(), IsPlaying(), VideoQueue().IsFinished(), VideoQueue().GetSize(), mVideoFrameEndTime, mHasVideo, mVideoSinkEndRequest.Exists(), mEndPromiseHolder.IsEmpty()) diff --git a/dom/media/mediasource/MediaSourceDemuxer.cpp b/dom/media/mediasource/MediaSourceDemuxer.cpp index db3d1a49b861..f932fd905838 100644 --- a/dom/media/mediasource/MediaSourceDemuxer.cpp +++ b/dom/media/mediasource/MediaSourceDemuxer.cpp @@ -254,7 +254,7 @@ MediaSourceDemuxer::GetMozDebugReaderData(nsACString& aString) result += nsPrintfCString("Dumping data for demuxer %p:\n", this); if (mAudioTrack) { result += nsPrintfCString("\tDumping Audio Track Buffer(%s): - mLastAudioTime: %f\n" - "\t\tNumSamples:%u Size:%u Evictable:%u NextGetSampleIndex:%u NextInsertionIndex:%d\n", + "\t\tNumSamples:%" PRIuSIZE " Size:%u Evictable:%u NextGetSampleIndex:%u NextInsertionIndex:%d\n", mAudioTrack->mAudioTracks.mInfo->mMimeType.get(), mAudioTrack->mAudioTracks.mNextSampleTime.ToSeconds(), mAudioTrack->mAudioTracks.mBuffers[0].Length(), @@ -268,7 +268,7 @@ MediaSourceDemuxer::GetMozDebugReaderData(nsACString& aString) } if (mVideoTrack) { result += nsPrintfCString("\tDumping Video Track Buffer(%s) - mLastVideoTime: %f\n" - "\t\tNumSamples:%u Size:%u Evictable:%u NextGetSampleIndex:%u NextInsertionIndex:%d\n", + "\t\tNumSamples:%" PRIuSIZE " Size:%u Evictable:%u NextGetSampleIndex:%u NextInsertionIndex:%d\n", mVideoTrack->mVideoTracks.mInfo->mMimeType.get(), mVideoTrack->mVideoTracks.mNextSampleTime.ToSeconds(), mVideoTrack->mVideoTracks.mBuffers[0].Length(), diff --git a/dom/media/platforms/apple/AppleATDecoder.cpp b/dom/media/platforms/apple/AppleATDecoder.cpp index 869c9ede7370..0eb303bce4fc 100644 --- a/dom/media/platforms/apple/AppleATDecoder.cpp +++ b/dom/media/platforms/apple/AppleATDecoder.cpp @@ -269,7 +269,7 @@ AppleATDecoder::DecodeSample(MediaRawData* aSample) LOG("Error decoding audio sample: %d\n", static_cast(rv)); return MediaResult(NS_ERROR_DOM_MEDIA_DECODE_ERR, RESULT_DETAIL("Error decoding audio sample: %d @ %lld", - rv, aSample->mTime)); + static_cast(rv), aSample->mTime)); } if (numFrames) { diff --git a/dom/plugins/base/nsPluginStreamListenerPeer.cpp b/dom/plugins/base/nsPluginStreamListenerPeer.cpp index 0012400c2ec5..766d01608245 100644 --- a/dom/plugins/base/nsPluginStreamListenerPeer.cpp +++ b/dom/plugins/base/nsPluginStreamListenerPeer.cpp @@ -1157,7 +1157,7 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIRequest *request, uint32_t major, minor; if (NS_SUCCEEDED(httpChannelInternal->GetResponseVersion(&major, &minor))) { - ver = nsPrintfCString("/%lu.%lu", major, minor); + ver = nsPrintfCString("/%" PRIu32 ".%" PRIu32, major, minor); } } @@ -1168,7 +1168,7 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIRequest *request, } // Assemble everything and pass to listener. - nsPrintfCString status("HTTP%s %lu %s", ver.get(), statusNum, + nsPrintfCString status("HTTP%s %" PRIu32 " %s", ver.get(), statusNum, statusText.get()); static_cast(mPStreamListener)->StatusLine(status.get()); } diff --git a/dom/quota/ActorsParent.cpp b/dom/quota/ActorsParent.cpp index be6b40158ef7..20d878558ddf 100644 --- a/dom/quota/ActorsParent.cpp +++ b/dom/quota/ActorsParent.cpp @@ -1285,7 +1285,7 @@ ReportInternalError(const char* aFile, uint32_t aLine, const char* aStr) nsContentUtils::LogSimpleConsoleError( NS_ConvertUTF8toUTF16(nsPrintfCString( - "Quota %s: %s:%lu", aStr, aFile, aLine)), + "Quota %s: %s:%" PRIu32, aStr, aFile, aLine)), "quota"); } @@ -4334,7 +4334,7 @@ QuotaManager::EnsureStorageIsInitialized() // Set the page size first. if (kSQLitePageSizeOverride) { rv = connection->ExecuteSimpleSQL( - nsPrintfCString("PRAGMA page_size = %lu;", kSQLitePageSizeOverride) + nsPrintfCString("PRAGMA page_size = %" PRIu32 ";", kSQLitePageSizeOverride) ); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp index de9128a283bb..82b311a7e825 100644 --- a/dom/workers/ScriptLoader.cpp +++ b/dom/workers/ScriptLoader.cpp @@ -2182,9 +2182,9 @@ void ReportLoadError(ErrorResult& aRv, nsresult aLoadResult, // We don't want to throw a JS exception, because for toplevel script // loads that would get squelched. aRv.ThrowDOMException(NS_ERROR_DOM_NETWORK_ERR, - nsPrintfCString("Failed to load worker script at %s (nsresult = 0x%x)", + nsPrintfCString("Failed to load worker script at %s (nsresult = 0x%" PRIx32 ")", NS_ConvertUTF16toUTF8(aScriptURL).get(), - aLoadResult)); + static_cast(aLoadResult))); return; } diff --git a/dom/xslt/xpath/txMozillaXPathTreeWalker.cpp b/dom/xslt/xpath/txMozillaXPathTreeWalker.cpp index 1387097e1705..0bb17451be77 100644 --- a/dom/xslt/xpath/txMozillaXPathTreeWalker.cpp +++ b/dom/xslt/xpath/txMozillaXPathTreeWalker.cpp @@ -539,8 +539,8 @@ txXPathNodeUtils::getOwnerDocument(const txXPathNode& aNode) return new txXPathNode(aNode.mNode->OwnerDoc()); } -const char gPrintfFmt[] = "id0x%p"; -const char gPrintfFmtAttr[] = "id0x%p-%010i"; +const char gPrintfFmt[] = "id0x%" PRIxPTR; +const char gPrintfFmtAttr[] = "id0x%" PRIxPTR "-%010i"; /* static */ nsresult diff --git a/dom/xslt/xslt/txEXSLTFunctions.cpp b/dom/xslt/xslt/txEXSLTFunctions.cpp index b226d908870e..f1719d574d05 100644 --- a/dom/xslt/xslt/txEXSLTFunctions.cpp +++ b/dom/xslt/xslt/txEXSLTFunctions.cpp @@ -639,8 +639,6 @@ txEXSLTFunctionCall::evaluate(txIEvalContext *aContext, case DATE_TIME: { // http://exslt.org/date/functions/date-time/ - // format: YYYY-MM-DDTTHH:MM:SS.sss+00:00 - char formatstr[] = "%04hd-%02ld-%02ldT%02ld:%02ld:%02ld.%03ld%c%02ld:%02ld"; PRExplodedTime prtime; PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &prtime); @@ -655,7 +653,10 @@ txEXSLTFunctionCall::evaluate(txIEvalContext *aContext, rv = aContext->recycler()->getStringResult(&strRes); NS_ENSURE_SUCCESS(rv, rv); - CopyASCIItoUTF16(nsPrintfCString(formatstr, + // format: YYYY-MM-DDTTHH:MM:SS.sss+00:00 + CopyASCIItoUTF16(nsPrintfCString("%04hd-%02" PRId32 "-%02" PRId32 + "T%02" PRId32 ":%02" PRId32 ":%02" PRId32 + ".%03" PRId32 "%c%02" PRId32 ":%02" PRId32, prtime.tm_year, prtime.tm_month + 1, prtime.tm_mday, prtime.tm_hour, prtime.tm_min, prtime.tm_sec, prtime.tm_usec / 10000, diff --git a/gfx/gl/GLLibraryEGL.cpp b/gfx/gl/GLLibraryEGL.cpp index 786923fc64cf..f992d69b9015 100644 --- a/gfx/gl/GLLibraryEGL.cpp +++ b/gfx/gl/GLLibraryEGL.cpp @@ -223,7 +223,7 @@ public: tokenizer.CheckWhite() && tokenizer.Check(Tokenizer::TOKEN_INTEGER, intToken)) { *mFailureId = "FAILURE_ID_ANGLE_ID_"; - mFailureId->AppendPrintf("%i", intToken.AsInteger()); + mFailureId->AppendPrintf("%" PRIu64, intToken.AsInteger()); } else { *mFailureId = "FAILURE_ID_ANGLE_UNKNOWN"; } diff --git a/gfx/layers/Layers.cpp b/gfx/layers/Layers.cpp index 104314328b29..f61d97901774 100644 --- a/gfx/layers/Layers.cpp +++ b/gfx/layers/Layers.cpp @@ -22,6 +22,7 @@ #include "gfxUtils.h" // for gfxUtils, etc #include "gfx2DGlue.h" #include "mozilla/DebugOnly.h" // for DebugOnly +#include "mozilla/IntegerPrintfMacros.h" #include "mozilla/Telemetry.h" // for Accumulate #include "mozilla/ToString.h" #include "mozilla/gfx/2D.h" // for DrawTarget @@ -1872,20 +1873,20 @@ Layer::PrintInfo(std::stringstream& aStream, const char* aPrefix) aStream << " [scrollbar]"; } if (GetScrollbarDirection() == ScrollDirection::VERTICAL) { - aStream << nsPrintfCString(" [vscrollbar=%lld]", GetScrollbarTargetContainerId()).get(); + aStream << nsPrintfCString(" [vscrollbar=%" PRIu64 "]", GetScrollbarTargetContainerId()).get(); } if (GetScrollbarDirection() == ScrollDirection::HORIZONTAL) { - aStream << nsPrintfCString(" [hscrollbar=%lld]", GetScrollbarTargetContainerId()).get(); + aStream << nsPrintfCString(" [hscrollbar=%" PRIu64 "]", GetScrollbarTargetContainerId()).get(); } if (GetIsFixedPosition()) { LayerPoint anchor = GetFixedPositionAnchor(); - aStream << nsPrintfCString(" [isFixedPosition scrollId=%lld sides=0x%x anchor=%s]", + aStream << nsPrintfCString(" [isFixedPosition scrollId=%" PRIu64 " sides=0x%x anchor=%s]", GetFixedPositionScrollContainerId(), GetFixedPositionSides(), ToString(anchor).c_str()).get(); } if (GetIsStickyPosition()) { - aStream << nsPrintfCString(" [isStickyPosition scrollId=%d outer=(%.3f,%.3f)-(%.3f,%.3f) " + aStream << nsPrintfCString(" [isStickyPosition scrollId=%" PRIu64 " outer=(%.3f,%.3f)-(%.3f,%.3f) " "inner=(%.3f,%.3f)-(%.3f,%.3f)]", GetStickyScrollContainerId(), GetStickyScrollRangeOuter().x, diff --git a/gfx/layers/LayersLogging.cpp b/gfx/layers/LayersLogging.cpp index 8af482785d88..4d4aa752060f 100644 --- a/gfx/layers/LayersLogging.cpp +++ b/gfx/layers/LayersLogging.cpp @@ -190,10 +190,10 @@ AppendToString(std::stringstream& aStream, const FrameMetrics& m, AppendToString(aStream, m.GetCumulativeResolution(), " cr="); AppendToString(aStream, m.GetZoom(), " z="); AppendToString(aStream, m.GetExtraResolution(), " er="); - aStream << nsPrintfCString(")] [u=(%d %d %lu)", + aStream << nsPrintfCString(")] [u=(%d %d %" PRIu32 ")", m.GetScrollUpdateType(), m.GetDoSmoothScroll(), m.GetScrollGeneration()).get(); - aStream << nsPrintfCString("] [i=(%ld %lld %d)] }", + aStream << nsPrintfCString("] [i=(%" PRIu32 " %" PRIu64 " %d)] }", m.GetPresShellId(), m.GetScrollId(), m.IsRootContent()).get(); } aStream << sfx; diff --git a/ipc/glue/ProtocolUtils.cpp b/ipc/glue/ProtocolUtils.cpp index 96f2046db192..d91833af410a 100644 --- a/ipc/glue/ProtocolUtils.cpp +++ b/ipc/glue/ProtocolUtils.cpp @@ -11,6 +11,8 @@ #include #endif +#include "mozilla/IntegerPrintfMacros.h" + #include "mozilla/ipc/ProtocolUtils.h" #include "mozilla/dom/ContentParent.h" @@ -232,7 +234,7 @@ AnnotateSystemError() if (error) { CrashReporter::AnnotateCrashReport( NS_LITERAL_CSTRING("IPCSystemError"), - nsPrintfCString("%lld", error)); + nsPrintfCString("%" PRId64, error)); } } #endif diff --git a/js/ipc/JavaScriptLogging.h b/js/ipc/JavaScriptLogging.h index 187579a4b5b4..e91b4a74d1c4 100644 --- a/js/ipc/JavaScriptLogging.h +++ b/js/ipc/JavaScriptLogging.h @@ -120,7 +120,7 @@ class Logging ptr = nullptr; } - out = nsPrintfCString("<%s %s:%d:%p>", side, objDesc, id.serialNumber(), ptr); + out = nsPrintfCString("<%s %s:%" PRIu64 ":%p>", side, objDesc, id.serialNumber(), ptr); } void format(const ReceiverObj& obj, nsCString& out) { diff --git a/js/xpconnect/src/XPCJSContext.cpp b/js/xpconnect/src/XPCJSContext.cpp index b22bba564344..7cc451990926 100644 --- a/js/xpconnect/src/XPCJSContext.cpp +++ b/js/xpconnect/src/XPCJSContext.cpp @@ -1954,7 +1954,7 @@ ReportZoneStats(const JS::ZoneStats& zStats, bool truncated = notableString.Length() < info.length; nsCString path = pathPrefix + - nsPrintfCString("strings/" STRING_LENGTH "%d, copies=%d, \"%s\"%s)/", + nsPrintfCString("strings/" STRING_LENGTH "%" PRIuSIZE ", copies=%d, \"%s\"%s)/", info.length, info.numCopies, escapedString.get(), truncated ? " (truncated)" : ""); diff --git a/layout/base/PositionedEventTargeting.cpp b/layout/base/PositionedEventTargeting.cpp index 8374ab9d299e..6fde724ab54f 100644 --- a/layout/base/PositionedEventTargeting.cpp +++ b/layout/base/PositionedEventTargeting.cpp @@ -127,17 +127,13 @@ GetPrefsFor(EventClassID aEventClassID) nsPrintfCString repositionPref("ui.%s.radius.reposition", prefBranch); Preferences::AddBoolVarCache(&prefs->mRepositionEventCoords, repositionPref.get(), false); - nsPrintfCString touchClusterPref("ui.zoomedview.enabled", prefBranch); - Preferences::AddBoolVarCache(&prefs->mTouchClusterDetectionEnabled, touchClusterPref.get(), false); + Preferences::AddBoolVarCache(&prefs->mTouchClusterDetectionEnabled, "ui.zoomedview.enabled", false); - nsPrintfCString simplifiedClusterDetectionPref("ui.zoomedview.simplified", prefBranch); - Preferences::AddBoolVarCache(&prefs->mSimplifiedClusterDetection, simplifiedClusterDetectionPref.get(), false); + Preferences::AddBoolVarCache(&prefs->mSimplifiedClusterDetection, "ui.zoomedview.simplified", false); - nsPrintfCString limitReadableSizePref("ui.zoomedview.limitReadableSize", prefBranch); - Preferences::AddUintVarCache(&prefs->mLimitReadableSize, limitReadableSizePref.get(), 8); + Preferences::AddUintVarCache(&prefs->mLimitReadableSize, "ui.zoomedview.limitReadableSize", 8); - nsPrintfCString keepLimitSize("ui.zoomedview.keepLimitSize", prefBranch); - Preferences::AddUintVarCache(&prefs->mKeepLimitSizeForCluster, keepLimitSize.get(), 16); + Preferences::AddUintVarCache(&prefs->mKeepLimitSizeForCluster, "ui.zoomedview.keepLimitSize", 16); } return prefs; diff --git a/layout/generic/nsFrameState.cpp b/layout/generic/nsFrameState.cpp index 92b8e8324dfb..9aa6068c6ad8 100644 --- a/layout/generic/nsFrameState.cpp +++ b/layout/generic/nsFrameState.cpp @@ -62,7 +62,7 @@ GetFrameState(nsIFrame* aFrame) #undef FRAME_STATE_BIT if (state) { - result.AppendPrintf(" | 0x%0llx", state); + result.AppendPrintf(" | 0x%0" PRIx64, static_cast(state)); } return result; diff --git a/layout/style/nsLayoutStylesheetCache.cpp b/layout/style/nsLayoutStylesheetCache.cpp index 81dafeaa1a06..a28d943410a5 100644 --- a/layout/style/nsLayoutStylesheetCache.cpp +++ b/layout/style/nsLayoutStylesheetCache.cpp @@ -498,7 +498,7 @@ ListInterestingFiles(nsString& aAnnotation, nsIFile* aFile, aAnnotation.AppendLiteral(" ("); int64_t size; if (NS_SUCCEEDED(aFile->GetFileSize(&size))) { - aAnnotation.AppendPrintf("%ld", size); + aAnnotation.AppendPrintf("%" PRId64, size); } else { aAnnotation.AppendLiteral("???"); } @@ -601,7 +601,8 @@ AnnotateCrashReport(nsIURI* aURI) nsAutoCString resolvedSpec; nsresult rv = handler->ResolveURI(aURI, resolvedSpec); if (NS_FAILED(rv)) { - annotation.AppendPrintf("(ResolveURI failed with 0x%08x)\n", rv); + annotation.AppendPrintf("(ResolveURI failed with 0x%08" PRIx32 ")\n", + static_cast(rv)); } annotation.Append(NS_ConvertUTF8toUTF16(resolvedSpec)); annotation.Append('\n'); @@ -694,7 +695,8 @@ AnnotateCrashReport(nsIURI* aURI) nsZipFind* find; rv = zip->FindInit(nullptr, &find); if (NS_FAILED(rv)) { - annotation.AppendPrintf(" (FindInit failed with 0x%08x)\n", rv); + annotation.AppendPrintf(" (FindInit failed with 0x%08" PRIx32 ")\n", + static_cast(rv)); } else if (!find) { annotation.AppendLiteral(" (FindInit returned null)\n"); } else { @@ -784,7 +786,7 @@ nsLayoutStylesheetCache::LoadSheet(nsIURI* aURI, nsresult rv = loader->LoadSheetSync(aURI, aParsingMode, true, aSheet); if (NS_FAILED(rv)) { ErrorLoadingSheet(aURI, - nsPrintfCString("LoadSheetSync failed with error %x", rv).get(), + nsPrintfCString("LoadSheetSync failed with error %" PRIx32, static_cast(rv)).get(), aFailureAction); } } diff --git a/layout/style/nsStyleUtil.cpp b/layout/style/nsStyleUtil.cpp index 60663b4a350f..40bff65e5c17 100644 --- a/layout/style/nsStyleUtil.cpp +++ b/layout/style/nsStyleUtil.cpp @@ -95,7 +95,7 @@ void nsStyleUtil::AppendEscapedCSSString(const nsAString& aString, 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("\\%x ", *in); } else { if (*in == '"' || *in == '\'' || *in == '\\') { // Escape backslash and quote characters symbolically. @@ -149,7 +149,7 @@ nsStyleUtil::AppendEscapedCSSIdent(const nsAString& aIdent, nsAString& aReturn) // 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("\\%x ", *in); ++in; } @@ -159,7 +159,7 @@ nsStyleUtil::AppendEscapedCSSIdent(const nsAString& aIdent, nsAString& aReturn) aReturn.Append(char16_t(0xFFFD)); } else 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("\\%x ", *in); } else { // Escape ASCII non-identifier printables as a backslash plus // the character. diff --git a/netwerk/cache/nsDiskCacheDeviceSQL.cpp b/netwerk/cache/nsDiskCacheDeviceSQL.cpp index 38e0d6090502..b28bbff89eb2 100644 --- a/netwerk/cache/nsDiskCacheDeviceSQL.cpp +++ b/netwerk/cache/nsDiskCacheDeviceSQL.cpp @@ -2327,7 +2327,7 @@ nsOfflineCacheDevice::CreateApplicationCache(const nsACString &group, // Include the timestamp to guarantee uniqueness across runs, and // the gNextTemporaryClientID for uniqueness within a second. - clientID.Append(nsPrintfCString("|%016lld|%d", + clientID.Append(nsPrintfCString("|%016" PRId64 "|%d", now / PR_USEC_PER_SEC, gNextTemporaryClientID++)); diff --git a/netwerk/protocol/http/ConnectionDiagnostics.cpp b/netwerk/protocol/http/ConnectionDiagnostics.cpp index 9ddc8e362b53..c70a32eceaba 100644 --- a/netwerk/protocol/http/ConnectionDiagnostics.cpp +++ b/netwerk/protocol/http/ConnectionDiagnostics.cpp @@ -16,6 +16,9 @@ #include "nsServiceManagerUtils.h" #include "nsSocketTransportService2.h" +#include "mozilla/IntegerPrintfMacros.h" +#include "mozilla/SizePrintfMacros.h" + namespace mozilla { namespace net { @@ -50,15 +53,15 @@ nsHttpConnectionMgr::OnMsgPrintDiagnostics(int32_t, ARefBase *) AtActiveConnectionLimit(ent, NS_HTTP_ALLOW_KEEPALIVE)); mLogData.AppendPrintf(" RestrictConnections = %d\n", RestrictConnections(ent)); - mLogData.AppendPrintf(" Pending Q Length = %u\n", + mLogData.AppendPrintf(" Pending Q Length = %" PRIuSIZE "\n", ent->mPendingQ.Length()); - mLogData.AppendPrintf(" Active Conns Length = %u\n", + mLogData.AppendPrintf(" Active Conns Length = %" PRIuSIZE "\n", ent->mActiveConns.Length()); - mLogData.AppendPrintf(" Idle Conns Length = %u\n", + mLogData.AppendPrintf(" Idle Conns Length = %" PRIuSIZE "\n", ent->mIdleConns.Length()); - mLogData.AppendPrintf(" Half Opens Length = %u\n", + mLogData.AppendPrintf(" Half Opens Length = %" PRIuSIZE "\n", ent->mHalfOpens.Length()); - mLogData.AppendPrintf(" Coalescing Keys Length = %u\n", + mLogData.AppendPrintf(" Coalescing Keys Length = %" PRIuSIZE "\n", ent->mCoalescingKeys.Length()); mLogData.AppendPrintf(" Spdy using = %d, preferred = %d\n", ent->mUsingSpdy, ent->mInPreferredHash); @@ -141,7 +144,7 @@ nsHttpConnection::PrintDiagnostics(nsCString &log) 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)); @@ -173,7 +176,7 @@ Http2Session::PrintDiagnostics(nsCString &log) mStreamTransactionHash.Count(), mStreamIDHash.Count()); - log.AppendPrintf(" Queued Stream Size = %d\n", mQueuedStreams.GetSize()); + log.AppendPrintf(" Queued Stream Size = %" PRIuSIZE "\n", mQueuedStreams.GetSize()); PRIntervalTime now = PR_IntervalNow(); log.AppendPrintf(" Ping Threshold = %ums\n", diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index 2d6a542f8276..bd78a2286402 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -3649,7 +3649,7 @@ nsHttpChannel::OpenCacheEntry(bool isHttps) cacheEntryOpenFlags |= nsICacheStorage::OPEN_BYPASS_IF_BUSY; if (PossiblyIntercepted()) { - extension.Append(nsPrintfCString("u%lld", mInterceptionID)); + extension.Append(nsPrintfCString("u%" PRIu64, mInterceptionID)); } else if (mPostID) { extension.Append(nsPrintfCString("%d", mPostID)); } diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp index d8eee22c70fc..98e39bd81dd9 100644 --- a/netwerk/protocol/http/nsHttpHandler.cpp +++ b/netwerk/protocol/http/nsHttpHandler.cpp @@ -895,7 +895,8 @@ nsHttpHandler::InitUserAgentComponents() #endif SInt32 majorVersion = nsCocoaFeatures::OSXVersionMajor(); SInt32 minorVersion = nsCocoaFeatures::OSXVersionMinor(); - mOscpu += nsPrintfCString(" %d.%d", majorVersion, minorVersion); + mOscpu += nsPrintfCString(" %d.%d", static_cast(majorVersion), + static_cast(minorVersion)); #elif defined (XP_UNIX) struct utsname name; diff --git a/netwerk/protocol/http/nsHttpResponseHead.cpp b/netwerk/protocol/http/nsHttpResponseHead.cpp index 6d384c48872e..dae8a9fc0219 100644 --- a/netwerk/protocol/http/nsHttpResponseHead.cpp +++ b/netwerk/protocol/http/nsHttpResponseHead.cpp @@ -229,7 +229,7 @@ nsHttpResponseHead::SetContentLength(int64_t len) mHeaders.ClearHeader(nsHttp::Content_Length); else mHeaders.SetHeader(nsHttp::Content_Length, - nsPrintfCString("%lld", len), + nsPrintfCString("%" PRId64, len), false, nsHttpHeaderArray::eVarietyResponse); } diff --git a/toolkit/components/filepicker/nsFileView.cpp b/toolkit/components/filepicker/nsFileView.cpp index 257bfdec3c33..f9d038f20d2b 100644 --- a/toolkit/components/filepicker/nsFileView.cpp +++ b/toolkit/components/filepicker/nsFileView.cpp @@ -735,7 +735,7 @@ nsFileView::GetCellText(int32_t aRow, nsITreeColumn* aCol, else { int64_t fileSize; curFile->GetFileSize(&fileSize); - CopyUTF8toUTF16(nsPrintfCString("%lld", fileSize), aCellText); + CopyUTF8toUTF16(nsPrintfCString("%" PRId64, fileSize), aCellText); } } diff --git a/toolkit/components/places/nsNavBookmarks.cpp b/toolkit/components/places/nsNavBookmarks.cpp index 0844a9c08c88..a2be28cba568 100644 --- a/toolkit/components/places/nsNavBookmarks.cpp +++ b/toolkit/components/places/nsNavBookmarks.cpp @@ -1666,7 +1666,7 @@ nsNavBookmarks::SetItemDateAdded(int64_t aItemId, PRTime aDateAdded, OnItemChanged(bookmark.id, NS_LITERAL_CSTRING("dateAdded"), false, - nsPrintfCString("%lld", bookmark.dateAdded), + nsPrintfCString("%" PRId64, bookmark.dateAdded), bookmark.dateAdded, bookmark.type, bookmark.parentId, @@ -1736,7 +1736,7 @@ nsNavBookmarks::SetItemLastModified(int64_t aItemId, PRTime aLastModified, OnItemChanged(bookmark.id, NS_LITERAL_CSTRING("lastModified"), false, - nsPrintfCString("%lld", bookmark.lastModified), + nsPrintfCString("%" PRId64, bookmark.lastModified), bookmark.lastModified, bookmark.type, bookmark.parentId, diff --git a/toolkit/components/places/nsNavHistory.cpp b/toolkit/components/places/nsNavHistory.cpp index e0a3296e1423..496a80eb7b33 100644 --- a/toolkit/components/places/nsNavHistory.cpp +++ b/toolkit/components/places/nsNavHistory.cpp @@ -7,6 +7,8 @@ #include #include "mozilla/DebugOnly.h" +#include "mozilla/IntegerPrintfMacros.h" +#include "mozilla/SizePrintfMacros.h" #include "nsNavHistory.h" @@ -210,7 +212,7 @@ void GetTagsSqlFragment(int64_t aTagsFolder, "JOIN moz_bookmarks t_t ON t_t.id = +b_t.parent " "WHERE b_t.fk = ") + aRelation + NS_LITERAL_CSTRING(" " "AND t_t.parent = ") + - nsPrintfCString("%lld", aTagsFolder) + NS_LITERAL_CSTRING(" " + nsPrintfCString("%" PRId64, aTagsFolder) + NS_LITERAL_CSTRING(" " ")")); } @@ -1553,7 +1555,7 @@ PlacesSQLQueryBuilder::SelectAsURI() "LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id " "WHERE NOT EXISTS ( " "SELECT id FROM moz_bookmarks WHERE id = b2.parent AND parent = ") + - nsPrintfCString("%lld", history->GetTagsFolder()) + + nsPrintfCString("%" PRId64, history->GetTagsFolder()) + NS_LITERAL_CSTRING(") " "ORDER BY b2.fk DESC, b2.lastModified DESC"); } @@ -1574,7 +1576,7 @@ PlacesSQLQueryBuilder::SelectAsURI() "WHERE NOT EXISTS " "(SELECT id FROM moz_bookmarks " "WHERE id = b.parent AND parent = ") + - nsPrintfCString("%lld", history->GetTagsFolder()) + + nsPrintfCString("%" PRId64, history->GetTagsFolder()) + NS_LITERAL_CSTRING(") " "{ADDITIONAL_CONDITIONS}"); } @@ -1634,7 +1636,7 @@ PlacesSQLQueryBuilder::SelectAsDay() // insert position in a result. mQueryString = nsPrintfCString( "SELECT null, " - "'place:type=%ld&sort=%ld&beginTime='||beginTime||'&endTime='||endTime, " + "'place:type=%d&sort=%d&beginTime='||beginTime||'&endTime='||endTime, " "dayTitle, null, null, beginTime, null, null, null, null, null, null, " "null, null, null " "FROM (", // TOUTER BEGIN @@ -1838,7 +1840,7 @@ PlacesSQLQueryBuilder::SelectAsSite() } mQueryString = nsPrintfCString( - "SELECT null, 'place:type=%ld&sort=%ld&domain=&domainIsHost=true'%s, " + "SELECT null, 'place:type=%d&sort=%d&domain=&domainIsHost=true'%s, " ":localhost, :localhost, null, null, null, null, null, null, null, " "null, null, null " "WHERE EXISTS ( " @@ -1853,7 +1855,7 @@ PlacesSQLQueryBuilder::SelectAsSite() ") " "UNION ALL " "SELECT null, " - "'place:type=%ld&sort=%ld&domain='||host||'&domainIsHost=true'%s, " + "'place:type=%d&sort=%d&domain='||host||'&domainIsHost=true'%s, " "host, host, null, null, null, null, null, null, null, " "null, null, null " "FROM ( " @@ -1893,11 +1895,11 @@ PlacesSQLQueryBuilder::SelectAsTag() mHasDateColumns = true; mQueryString = nsPrintfCString( - "SELECT null, 'place:folder=' || id || '&queryType=%d&type=%ld', " + "SELECT null, 'place:folder=' || id || '&queryType=%d&type=%d', " "title, null, null, null, null, null, dateAdded, " "lastModified, null, null, null, null, null, null " "FROM moz_bookmarks " - "WHERE parent = %lld", + "WHERE parent = %" PRId64, nsINavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS, nsINavHistoryQueryOptions::RESULTS_AS_TAG_CONTENTS, history->GetTagsFolder() @@ -3356,7 +3358,7 @@ nsNavHistory::QueryToSelectClause(nsNavHistoryQuery* aQuery, // const clause.Condition("b.parent IN("); for (nsTArray::size_type i = 0; i < includeFolders.Length(); ++i) { - clause.Str(nsPrintfCString("%lld", includeFolders[i]).get()); + clause.Str(nsPrintfCString("%" PRId64, includeFolders[i]).get()); if (i < includeFolders.Length() - 1) { clause.Str(","); } diff --git a/toolkit/components/telemetry/WebrtcTelemetry.cpp b/toolkit/components/telemetry/WebrtcTelemetry.cpp index 29c22be23581..a437bff22f31 100644 --- a/toolkit/components/telemetry/WebrtcTelemetry.cpp +++ b/toolkit/components/telemetry/WebrtcTelemetry.cpp @@ -46,7 +46,7 @@ ReflectIceEntry(const WebrtcTelemetry::WebrtcIceCandidateType *entry, if (!statsObj) return false; if (!JS_DefineProperty(cx, obj, - nsPrintfCString("%lu", bitmask).BeginReading(), + nsPrintfCString("%" PRIu32, bitmask).BeginReading(), statsObj, JSPROP_ENUMERATE)) { return false; } diff --git a/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp b/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp index add034650d69..242cdb39626c 100644 --- a/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp +++ b/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp @@ -39,7 +39,7 @@ static mozilla::LazyLogModule gUrlClassifierStreamUpdaterLog("UrlClassifierStrea // Calls nsIURLFormatter::TrimSensitiveURLs to remove sensitive // info from the logging message. -static void TrimAndLog(const char* aFmt, ...) +static MOZ_FORMAT_PRINTF(1, 2) void TrimAndLog(const char* aFmt, ...) { nsString raw; @@ -404,7 +404,8 @@ nsUrlClassifierStreamUpdater::StreamFinished(nsresult status, // We are a service and may not be reset with Init between calls, so reset // mBeganStream manually. mBeganStream = false; - LOG(("nsUrlClassifierStreamUpdater::StreamFinished [%x, %d]", status, requestedDelay)); + LOG(("nsUrlClassifierStreamUpdater::StreamFinished [%" PRIx32 ", %d]", + static_cast(status), requestedDelay)); if (NS_FAILED(status) || mPendingUpdates.Length() == 0) { // We're done. LOG(("nsUrlClassifierStreamUpdater::Done [this=%p]", this)); @@ -710,7 +711,7 @@ nsUrlClassifierStreamUpdater::OnDataAvailable(nsIRequest *request, LOG(("OnDataAvailable (%d bytes)", aLength)); if (aSourceOffset > MAX_FILE_SIZE) { - LOG(("OnDataAvailable::Abort because exceeded the maximum file size(%lld)", aSourceOffset)); + LOG(("OnDataAvailable::Abort because exceeded the maximum file size(%" PRIu64 ")", aSourceOffset)); return NS_ERROR_FILE_TOO_BIG; } @@ -735,8 +736,8 @@ nsUrlClassifierStreamUpdater::OnStopRequest(nsIRequest *request, nsISupports* co if (!mDBService) return NS_ERROR_NOT_INITIALIZED; - LOG(("OnStopRequest (status %x, beganStream %s, this=%p)", aStatus, - mBeganStream ? "true" : "false", this)); + LOG(("OnStopRequest (status %" PRIx32 ", beganStream %s, this=%p)", + static_cast(aStatus), mBeganStream ? "true" : "false", this)); nsresult rv; diff --git a/toolkit/xre/ProfileReset.cpp b/toolkit/xre/ProfileReset.cpp index de15ba005c9c..43781b6ea847 100644 --- a/toolkit/xre/ProfileReset.cpp +++ b/toolkit/xre/ProfileReset.cpp @@ -47,7 +47,7 @@ CreateResetProfile(nsIToolkitProfileService* aProfileSvc, const nsACString& aOld } else { newProfileName.Assign("default-"); } - newProfileName.Append(nsPrintfCString("%lld", PR_Now() / 1000)); + newProfileName.Append(nsPrintfCString("%" PRId64, PR_Now() / 1000)); nsresult rv = aProfileSvc->CreateProfile(nullptr, // choose a default dir for us newProfileName, getter_AddRefs(newProfile)); diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index 74618be0e2e0..a4b5997eb004 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -4175,9 +4175,9 @@ XREMain::XRE_mainRun() } // Needs to be set after xpcom initialization. CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("FramePoisonBase"), - nsPrintfCString("%.16llx", uint64_t(gMozillaPoisonBase))); + nsPrintfCString("%.16" PRIu64, uint64_t(gMozillaPoisonBase))); CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("FramePoisonSize"), - nsPrintfCString("%lu", uint32_t(gMozillaPoisonSize))); + nsPrintfCString("%" PRIu32, uint32_t(gMozillaPoisonSize))); #ifdef XP_WIN PR_CreateThread(PR_USER_THREAD, AnnotateSystemManufacturer_ThreadStart, 0, diff --git a/tools/profiler/tasktracer/GeckoTaskTracer.h b/tools/profiler/tasktracer/GeckoTaskTracer.h index dc60105588a8..e52d6149110e 100644 --- a/tools/profiler/tasktracer/GeckoTaskTracer.h +++ b/tools/profiler/tasktracer/GeckoTaskTracer.h @@ -67,7 +67,7 @@ void ShutdownTaskTracer(); // Add a label to the currently running task, aFormat is the message to log, // followed by corresponding parameters. -void AddLabel(const char* aFormat, ...); +void AddLabel(const char* aFormat, ...) MOZ_FORMAT_PRINTF(1, 2); void StartLogging(); void StopLogging(); diff --git a/xpcom/base/SystemMemoryReporter.cpp b/xpcom/base/SystemMemoryReporter.cpp index 105b9c8cf1bd..e781a6aff842 100644 --- a/xpcom/base/SystemMemoryReporter.cpp +++ b/xpcom/base/SystemMemoryReporter.cpp @@ -461,7 +461,7 @@ private: aDesc.AppendPrintf("The stack size of a non-main thread named '%s' with " "thread ID %d. This corresponds to '[stack:%d]' " - "in /proc/%d/smaps.", threadName.get(), tid, tid); + "in /proc/%d/smaps.", threadName.get(), tid, tid, tid); } else if (absPath.EqualsLiteral("[vdso]")) { aName.AppendLiteral("vdso"); aDesc.AppendLiteral( diff --git a/xpcom/build/LateWriteChecks.cpp b/xpcom/build/LateWriteChecks.cpp index 3d1e0f5ac109..e1b2c7557de0 100644 --- a/xpcom/build/LateWriteChecks.cpp +++ b/xpcom/build/LateWriteChecks.cpp @@ -50,7 +50,7 @@ public: MozillaRegisterDebugFILE(mFile); } - void Printf(const char* aFormat, ...) + void Printf(const char* aFormat, ...) MOZ_FORMAT_PRINTF(2, 3) { MOZ_ASSERT(mFile); va_list list; diff --git a/xpcom/string/nsPrintfCString.h b/xpcom/string/nsPrintfCString.h index ce90ec497985..eb453916a98a 100644 --- a/xpcom/string/nsPrintfCString.h +++ b/xpcom/string/nsPrintfCString.h @@ -25,7 +25,7 @@ class nsPrintfCString : public nsFixedCString typedef nsCString string_type; public: - explicit nsPrintfCString(const char_type* aFormat, ...) + explicit nsPrintfCString(const char_type* aFormat, ...) MOZ_FORMAT_PRINTF(2, 3) : nsFixedCString(mLocalBuffer, kLocalBufferSize, 0) { va_list ap; diff --git a/xpcom/string/nsTSubstring.cpp b/xpcom/string/nsTSubstring.cpp index afa7dc831567..330cf1c8c5bc 100644 --- a/xpcom/string/nsTSubstring.cpp +++ b/xpcom/string/nsTSubstring.cpp @@ -7,6 +7,7 @@ #include "mozilla/CheckedInt.h" #include "mozilla/double-conversion.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/Printf.h" using double_conversion::DoubleToStringConverter; @@ -904,29 +905,41 @@ nsTSubstring_CharT::StripChars(const char_type* aChars, uint32_t aOffset) mLength = to - mData; } -int -nsTSubstring_CharT::AppendFunc(void* aArg, const char* aStr, uint32_t aLen) +struct MOZ_STACK_CLASS PrintfAppend_CharT : public mozilla::PrintfTarget { - self_type* self = static_cast(aArg); - - // NSPR sends us the final null terminator even though we don't want it - if (aLen && aStr[aLen - 1] == '\0') { - --aLen; + explicit PrintfAppend_CharT(nsTSubstring_CharT* aString) + : mString(aString) + { } - self->AppendASCII(aStr, aLen); + bool append(const char* aStr, size_t aLen) override { + if (aLen == 0) { + return true; + } - return aLen; -} + // Printf sends us the final null terminator even though we don't want it + if (aStr[aLen - 1] == '\0') { + --aLen; + } + + mString->AppendASCII(aStr, aLen); + return true; + } + +private: + + nsTSubstring_CharT* mString; +}; void nsTSubstring_CharT::AppendPrintf(const char* aFormat, ...) { + PrintfAppend_CharT appender(this); va_list ap; va_start(ap, aFormat); - uint32_t r = PR_vsxprintf(AppendFunc, this, aFormat, ap); - if (r == (uint32_t)-1) { - MOZ_CRASH("Allocation or other failure in PR_vsxprintf"); + bool r = appender.vprint(aFormat, ap); + if (!r) { + MOZ_CRASH("Allocation or other failure in PrintfTarget::print"); } va_end(ap); } @@ -934,9 +947,10 @@ nsTSubstring_CharT::AppendPrintf(const char* aFormat, ...) void nsTSubstring_CharT::AppendPrintf(const char* aFormat, va_list aAp) { - uint32_t r = PR_vsxprintf(AppendFunc, this, aFormat, aAp); - if (r == (uint32_t)-1) { - MOZ_CRASH("Allocation or other failure in PR_vsxprintf"); + PrintfAppend_CharT appender(this); + bool r = appender.vprint(aFormat, aAp); + if (!r) { + MOZ_CRASH("Allocation or other failure in PrintfTarget::print"); } } diff --git a/xpcom/string/nsTSubstring.h b/xpcom/string/nsTSubstring.h index 68e9e2fd2d06..f59054334a68 100644 --- a/xpcom/string/nsTSubstring.h +++ b/xpcom/string/nsTSubstring.h @@ -6,6 +6,7 @@ // IWYU pragma: private, include "nsString.h" #include "mozilla/Casting.h" +#include "mozilla/IntegerPrintfMacros.h" #include "mozilla/UniquePtr.h" #include "mozilla/MemoryReporting.h" @@ -574,46 +575,54 @@ public: } /** - * Append a formatted string to the current string. Uses the format - * codes documented in prprf.h + * Append a formatted string to the current string. Uses the + * standard printf format codes. */ - void AppendPrintf(const char* aFormat, ...); + 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); + AppendPrintf("%" PRId32, aInteger); } void AppendInt(int32_t aInteger, int aRadix) { - const char* fmt = aRadix == 10 ? "%d" : aRadix == 8 ? "%o" : "%x"; - AppendPrintf(fmt, aInteger); + if (aRadix == 10) { + AppendPrintf("%" PRId32, aInteger); + } else { + AppendPrintf(aRadix == 8 ? "%" PRIo32 : "%" PRIx32, + static_cast(aInteger)); + } } void AppendInt(uint32_t aInteger) { - AppendPrintf("%u", aInteger); + AppendPrintf("%" PRIu32, aInteger); } void AppendInt(uint32_t aInteger, int aRadix) { - const char* fmt = aRadix == 10 ? "%u" : aRadix == 8 ? "%o" : "%x"; - AppendPrintf(fmt, aInteger); + AppendPrintf(aRadix == 10 ? "%" PRIu32 : aRadix == 8 ? "%" PRIo32 : "%" PRIx32, + 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"; - AppendPrintf(fmt, aInteger); + if (aRadix == 10) { + AppendPrintf("%" PRId64, aInteger); + } else { + AppendPrintf(aRadix == 8 ? "%" PRIo64 : "%" PRIx64, + static_cast(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"; - AppendPrintf(fmt, aInteger); + AppendPrintf(aRadix == 10 ? "%" PRIu64 : aRadix == 8 ? "%" PRIo64 : "%" PRIx64, + aInteger); } /** @@ -1044,8 +1053,6 @@ protected: void NS_FASTCALL ReplaceLiteral(index_type aCutStart, size_type aCutLength, const char_type* aData, size_type aLength); - static int AppendFunc(void* aArg, const char* aStr, uint32_t aLen); - public: // NOTE: this method is declared public _only_ for convenience for diff --git a/xpcom/string/string-template-def-char.h b/xpcom/string/string-template-def-char.h index a84d66f1e179..a89855522080 100644 --- a/xpcom/string/string-template-def-char.h +++ b/xpcom/string/string-template-def-char.h @@ -12,6 +12,7 @@ #define nsTFixedString_CharT nsFixedCString #define nsTAutoString_CharT nsAutoCString #define nsTSubstring_CharT nsACString +#define PrintfAppend_CharT PrintfAppend_nsACString #define nsTSubstringTuple_CharT nsCSubstringTuple #define nsTStringComparator_CharT nsCStringComparator #define nsTDefaultStringComparator_CharT nsDefaultCStringComparator diff --git a/xpcom/string/string-template-def-unichar.h b/xpcom/string/string-template-def-unichar.h index 63653c7bfca1..03d74e9e8aca 100644 --- a/xpcom/string/string-template-def-unichar.h +++ b/xpcom/string/string-template-def-unichar.h @@ -12,6 +12,7 @@ #define nsTFixedString_CharT nsFixedString #define nsTAutoString_CharT nsAutoString #define nsTSubstring_CharT nsAString +#define PrintfAppend_CharT PrintfAppend_nsAString #define nsTSubstringTuple_CharT nsSubstringTuple #define nsTStringComparator_CharT nsStringComparator #define nsTDefaultStringComparator_CharT nsDefaultStringComparator diff --git a/xpcom/string/string-template-undef.h b/xpcom/string/string-template-undef.h index dedf7a6c2911..9d278803e543 100644 --- a/xpcom/string/string-template-undef.h +++ b/xpcom/string/string-template-undef.h @@ -13,6 +13,7 @@ #undef nsTFixedString_CharT #undef nsTAutoString_CharT #undef nsTSubstring_CharT +#undef PrintfAppend_CharT #undef nsTSubstringTuple_CharT #undef nsTStringComparator_CharT #undef nsTDefaultStringComparator_CharT