From c95577405871df1b10ffbeb6347c29d694bae8a6 Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Tue, 2 Aug 2016 22:16:15 +0200 Subject: [PATCH] Bug 1251364 - Remove our custom printf implementation (jsprf.cpp). r=tromey --- js/src/asmjs/WasmBinaryToAST.cpp | 2 +- js/src/builtin/SIMD.cpp | 4 +- js/src/builtin/TestingFunctions.cpp | 8 +- js/src/ctypes/CTypes.cpp | 43 +++---- js/src/ctypes/CTypes.h | 2 +- js/src/frontend/NameFunctions.cpp | 2 +- js/src/gc/Statistics.cpp | 164 +++++++++++++------------- js/src/gc/Tracer.cpp | 18 +-- js/src/gc/Verifier.cpp | 2 +- js/src/jit/BaselineBailouts.cpp | 14 +-- js/src/jit/CodeGenerator.cpp | 4 +- js/src/jit/JitSpewer.cpp | 4 +- js/src/jit/JitcodeMap.cpp | 2 +- js/src/jit/OptimizationTracking.cpp | 6 +- js/src/jit/arm/Assembler-arm.cpp | 6 +- js/src/jsapi.cpp | 2 +- js/src/jscntxt.cpp | 6 +- js/src/jsdate.cpp | 110 ++++++++--------- js/src/jsdtoa.cpp | 2 +- js/src/jsexn.cpp | 12 +- js/src/jsgc.cpp | 6 +- js/src/jsobj.cpp | 10 +- js/src/jsopcode.cpp | 6 +- js/src/jsprf.cpp | 66 ----------- js/src/jsprf.h | 8 -- js/src/jsscript.cpp | 6 +- js/src/shell/js.cpp | 4 +- js/src/vm/CharacterEncoding.cpp | 4 +- js/src/vm/CodeCoverage.cpp | 6 +- js/src/vm/Debugger.cpp | 2 +- js/src/vm/Interpreter.cpp | 2 +- js/src/vm/JSONParser.cpp | 4 +- js/src/vm/Printer.cpp | 2 +- js/src/vm/SPSProfiler.cpp | 4 +- js/src/vm/TraceLogging.cpp | 4 +- js/src/vm/TypeInference.cpp | 43 +++---- js/src/vm/TypeInference.h | 3 - js/xpconnect/src/XPCConvert.cpp | 2 +- js/xpconnect/src/XPCJSRuntime.cpp | 3 +- js/xpconnect/src/XPCWrappedJS.cpp | 5 +- js/xpconnect/src/XPCWrappedNative.cpp | 5 +- 41 files changed, 265 insertions(+), 343 deletions(-) diff --git a/js/src/asmjs/WasmBinaryToAST.cpp b/js/src/asmjs/WasmBinaryToAST.cpp index bdbabcc8a669..ab775316dd58 100644 --- a/js/src/asmjs/WasmBinaryToAST.cpp +++ b/js/src/asmjs/WasmBinaryToAST.cpp @@ -119,7 +119,7 @@ AstDecodeFail(AstDecodeContext& c, const char* str) { uint32_t offset = c.d.currentOffset(); char offsetStr[sizeof "4294967295"]; - JS_snprintf(offsetStr, sizeof offsetStr, "%" PRIu32, offset); + snprintf(offsetStr, sizeof offsetStr, "%" PRIu32, offset); JS_ReportErrorNumber(c.cx, GetErrorMessage, nullptr, JSMSG_WASM_DECODE_FAIL, offsetStr, str); return false; } diff --git a/js/src/builtin/SIMD.cpp b/js/src/builtin/SIMD.cpp index fa84b7fbab29..23bc32ca57cb 100644 --- a/js/src/builtin/SIMD.cpp +++ b/js/src/builtin/SIMD.cpp @@ -129,11 +129,11 @@ ErrorBadArgs(JSContext* cx) } static inline bool -ErrorWrongTypeArg(JSContext* cx, size_t argIndex, Handle typeDescr) +ErrorWrongTypeArg(JSContext* cx, unsigned argIndex, Handle typeDescr) { MOZ_ASSERT(argIndex < 10); char charArgIndex[2]; - JS_snprintf(charArgIndex, sizeof charArgIndex, "%d", argIndex); + snprintf(charArgIndex, sizeof charArgIndex, "%u", argIndex); HeapSlot& typeNameSlot = typeDescr->getReservedSlotRef(JS_DESCR_SLOT_STRING_REPR); char* typeNameStr = JS_EncodeString(cx, typeNameSlot.toString()); diff --git a/js/src/builtin/TestingFunctions.cpp b/js/src/builtin/TestingFunctions.cpp index 991f0322322a..c3b68f77c567 100644 --- a/js/src/builtin/TestingFunctions.cpp +++ b/js/src/builtin/TestingFunctions.cpp @@ -318,8 +318,8 @@ GC(JSContext* cx, unsigned argc, Value* vp) char buf[256] = { '\0' }; #ifndef JS_MORE_DETERMINISTIC - JS_snprintf(buf, sizeof(buf), "before %" PRIuSIZE ", after %" PRIuSIZE "\n", - preBytes, cx->runtime()->gc.usage.gcBytes()); + snprintf(buf, sizeof(buf), "before %" PRIuSIZE ", after %" PRIuSIZE "\n", + preBytes, cx->runtime()->gc.usage.gcBytes()); #endif JSString* str = JS_NewStringCopyZ(cx, buf); if (!str) @@ -2401,7 +2401,7 @@ ObjectAddress(JSContext* cx, unsigned argc, Value* vp) #else void* ptr = js::UncheckedUnwrap(&args[0].toObject(), true); char buffer[64]; - JS_snprintf(buffer, sizeof(buffer), "%p", ptr); + snprintf(buffer, sizeof(buffer), "%p", ptr); JSString* str = JS_NewStringCopyZ(cx, buffer); if (!str) @@ -2442,7 +2442,7 @@ SharedAddress(JSContext* cx, unsigned argc, Value* vp) } char buffer[64]; uint32_t nchar = - JS_snprintf(buffer, sizeof(buffer), "%p", + snprintf(buffer, sizeof(buffer), "%p", obj->as().dataPointerShared().unwrap(/*safeish*/)); JSString* str = JS_NewStringCopyN(cx, buffer, nchar); diff --git a/js/src/ctypes/CTypes.cpp b/js/src/ctypes/CTypes.cpp index dac5a7ecfcf0..0921430b6a5a 100644 --- a/js/src/ctypes/CTypes.cpp +++ b/js/src/ctypes/CTypes.cpp @@ -8,6 +8,7 @@ #include "mozilla/FloatingPoint.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/SizePrintfMacros.h" #include "mozilla/Vector.h" #include @@ -62,7 +63,6 @@ GetDeflatedUTF8StringLength(JSContext* maybecx, const CharT* chars, size_t nbytes; const CharT* end; unsigned c, c2; - char buffer[10]; nbytes = nchars; for (end = chars + nchars; chars != end; chars++) { @@ -94,7 +94,8 @@ GetDeflatedUTF8StringLength(JSContext* maybecx, const CharT* chars, bad_surrogate: if (maybecx) { js::gc::AutoSuppressGC suppress(maybecx); - JS_snprintf(buffer, 10, "0x%x", c); + char buffer[10]; + snprintf(buffer, sizeof(buffer), "0x%x", c); JS_ReportErrorFlagsAndNumber(maybecx, JSREPORT_ERROR, GetErrorMessage, nullptr, JSMSG_BAD_SURROGATE_CHAR, buffer); } @@ -1120,7 +1121,7 @@ ConvError(JSContext* cx, const char* expectedStr, HandleValue actual, MOZ_ASSERT(!funObj); char indexStr[16]; - JS_snprintf(indexStr, 16, "%u", arrIndex); + snprintf(indexStr, sizeof(indexStr), "%u", arrIndex); AutoString arrSource; JSAutoByteString arrBytes; @@ -1177,7 +1178,7 @@ ConvError(JSContext* cx, const char* expectedStr, HandleValue actual, MOZ_ASSERT(funObj); char indexStr[16]; - JS_snprintf(indexStr, 16, "%u", argIndex + 1); + snprintf(indexStr, sizeof(indexStr), "%u", argIndex + 1); AutoString funSource; JSAutoByteString funBytes; @@ -1260,7 +1261,7 @@ ArgumentConvError(JSContext* cx, HandleValue actual, const char* funStr, return false; char indexStr[16]; - JS_snprintf(indexStr, 16, "%u", argIndex + 1); + snprintf(indexStr, sizeof(indexStr), "%u", argIndex + 1); JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, CTYPESMSG_CONV_ERROR_ARG, valStr, indexStr, funStr); @@ -1289,9 +1290,9 @@ ArrayLengthMismatch(JSContext* cx, unsigned expectedLength, HandleObject arrObj, return false; char expectedLengthStr[16]; - JS_snprintf(expectedLengthStr, 16, "%u", expectedLength); + snprintf(expectedLengthStr, sizeof(expectedLengthStr), "%u", expectedLength); char actualLengthStr[16]; - JS_snprintf(actualLengthStr, 16, "%u", actualLength); + snprintf(actualLengthStr, sizeof(actualLengthStr), "%u", actualLength); AutoString arrSource; JSAutoByteString arrBytes; @@ -1319,9 +1320,9 @@ ArrayLengthOverflow(JSContext* cx, unsigned expectedLength, HandleObject arrObj, return false; char expectedLengthStr[16]; - JS_snprintf(expectedLengthStr, 16, "%u", expectedLength); + snprintf(expectedLengthStr, sizeof(expectedLengthStr), "%u", expectedLength); char actualLengthStr[16]; - JS_snprintf(actualLengthStr, 16, "%u", actualLength); + snprintf(actualLengthStr, sizeof(actualLengthStr), "%u", actualLength); AutoString arrSource; JSAutoByteString arrBytes; @@ -1426,9 +1427,9 @@ FieldCountMismatch(JSContext* cx, return false; char expectedCountStr[16]; - JS_snprintf(expectedCountStr, 16, "%u", expectedCount); + snprintf(expectedCountStr, sizeof(expectedCountStr), "%u", expectedCount); char actualCountStr[16]; - JS_snprintf(actualCountStr, 16, "%u", actualCount); + snprintf(actualCountStr, sizeof(actualCountStr), "%u", actualCount); JSAutoByteString posBytes; const char* posStr; @@ -1459,7 +1460,7 @@ FieldDescriptorCountError(JSContext* cx, Value val, size_t length) return false; char lengthStr[16]; - JS_snprintf(lengthStr, 16, "%u", length); + snprintf(lengthStr, sizeof(lengthStr), "%" PRIuSIZE, length); JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, CTYPESMSG_FIELD_DESC_COUNT, valStr, lengthStr); @@ -1594,9 +1595,9 @@ FunctionArgumentLengthMismatch(JSContext* cx, return false; char expectedCountStr[16]; - JS_snprintf(expectedCountStr, 16, "%u", expectedCount); + snprintf(expectedCountStr, sizeof(expectedCountStr), "%u", expectedCount); char actualCountStr[16]; - JS_snprintf(actualCountStr, 16, "%u", actualCount); + snprintf(actualCountStr, sizeof(actualCountStr), "%u", actualCount); const char* variadicStr = isVariadic ? " or more": ""; @@ -1617,7 +1618,7 @@ FunctionArgumentTypeError(JSContext* cx, return false; char indexStr[16]; - JS_snprintf(indexStr, 16, "%u", index + 1); + snprintf(indexStr, sizeof(indexStr), "%u", index + 1); JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, CTYPESMSG_ARG_TYPE_ERROR, indexStr, reason, valStr); @@ -1723,10 +1724,10 @@ static bool InvalidIndexRangeError(JSContext* cx, size_t index, size_t length) { char indexStr[16]; - JS_snprintf(indexStr, 16, "%u", index); + snprintf(indexStr, sizeof(indexStr), "%" PRIuSIZE, index); char lengthStr[16]; - JS_snprintf(lengthStr, 16, "%u", length); + snprintf(lengthStr, sizeof(lengthStr), "%" PRIuSIZE, length); JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, CTYPESMSG_INVALID_RANGE, indexStr, lengthStr); @@ -1883,8 +1884,8 @@ SizeMismatchCastError(JSContext* cx, char sourceSizeStr[16]; char targetSizeStr[16]; - JS_snprintf(sourceSizeStr, 16, "%u", sourceSize); - JS_snprintf(targetSizeStr, 16, "%u", targetSize); + snprintf(sourceSizeStr, sizeof(sourceSizeStr), "%" PRIuSIZE, sourceSize); + snprintf(targetSizeStr, sizeof(targetSizeStr), "%" PRIuSIZE, targetSize); JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, CTYPESMSG_SIZE_MISMATCH_CAST, @@ -1916,7 +1917,7 @@ VariadicArgumentTypeError(JSContext* cx, uint32_t index, HandleValue actual) return false; char indexStr[16]; - JS_snprintf(indexStr, 16, "%u", index + 1); + snprintf(indexStr, sizeof(indexStr), "%u", index + 1); JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, CTYPESMSG_VARG_TYPE_ERROR, indexStr, valStr); @@ -6305,7 +6306,7 @@ StructType::ConstructData(JSContext* cx, size_t count = fields->count(); if (count >= 2) { char fieldLengthStr[32]; - JS_snprintf(fieldLengthStr, 32, "0, 1, or %u", count); + snprintf(fieldLengthStr, sizeof(fieldLengthStr), "0, 1, or %" PRIuSIZE, count); return ArgumentLengthError(cx, "StructType constructor", fieldLengthStr, "s"); } diff --git a/js/src/ctypes/CTypes.h b/js/src/ctypes/CTypes.h index bf7bcc317ba8..6b1fc7804ea9 100644 --- a/js/src/ctypes/CTypes.h +++ b/js/src/ctypes/CTypes.h @@ -64,7 +64,7 @@ void AppendUInt(mozilla::Vector& v, unsigned n) { char array[16]; - size_t alen = JS_snprintf(array, 16, "%u", n); + size_t alen = snprintf(array, sizeof(array), "%u", n); size_t vlen = v.length(); if (!v.resize(vlen + alen)) return; diff --git a/js/src/frontend/NameFunctions.cpp b/js/src/frontend/NameFunctions.cpp index 37a239214bda..033291313199 100644 --- a/js/src/frontend/NameFunctions.cpp +++ b/js/src/frontend/NameFunctions.cpp @@ -55,7 +55,7 @@ class NameResolver /* Append a number to buf. */ bool appendNumber(double n) { char number[30]; - int digits = JS_snprintf(number, sizeof(number), "%g", n); + int digits = snprintf(number, sizeof(number), "%g", n); return buf->append(number, digits); } diff --git a/js/src/gc/Statistics.cpp b/js/src/gc/Statistics.cpp index cf886f60d7d5..49f3741faf68 100644 --- a/js/src/gc/Statistics.cpp +++ b/js/src/gc/Statistics.cpp @@ -341,11 +341,11 @@ Statistics::formatCompactSliceMessage() const "GC Slice %u - Pause: %.3fms of %s budget (@ %.3fms); Reason: %s; Reset: %s%s; Times: "; char buffer[1024]; memset(buffer, 0, sizeof(buffer)); - JS_snprintf(buffer, sizeof(buffer), format, index, - t(slice.duration()), budgetDescription, t(slice.start - slices[0].start), - ExplainReason(slice.reason), - slice.resetReason ? "yes - " : "no", - slice.resetReason ? slice.resetReason : ""); + snprintf(buffer, sizeof(buffer), format, index, + t(slice.duration()), budgetDescription, t(slice.start - slices[0].start), + ExplainReason(slice.reason), + slice.resetReason ? "yes - " : "no", + slice.resetReason ? slice.resetReason : ""); FragmentVector fragments; if (!fragments.append(DuplicateString(buffer)) || @@ -373,34 +373,34 @@ Statistics::formatCompactSummaryMessage() const char buffer[1024]; if (!nonincrementalReason_) { - JS_snprintf(buffer, sizeof(buffer), - "Max Pause: %.3fms; MMU 20ms: %.1f%%; MMU 50ms: %.1f%%; Total: %.3fms; ", - t(longest), mmu20 * 100., mmu50 * 100., t(total)); + snprintf(buffer, sizeof(buffer), + "Max Pause: %.3fms; MMU 20ms: %.1f%%; MMU 50ms: %.1f%%; Total: %.3fms; ", + t(longest), mmu20 * 100., mmu50 * 100., t(total)); } else { - JS_snprintf(buffer, sizeof(buffer), "Non-Incremental: %.3fms (%s); ", - t(total), nonincrementalReason_); + snprintf(buffer, sizeof(buffer), "Non-Incremental: %.3fms (%s); ", + t(total), nonincrementalReason_); } if (!fragments.append(DuplicateString(buffer))) return UniqueChars(nullptr); - JS_snprintf(buffer, sizeof(buffer), - "Zones: %d of %d (-%d); Compartments: %d of %d (-%d); HeapSize: %.3f MiB; "\ - "HeapChange (abs): %+d (%d); ", - zoneStats.collectedZoneCount, zoneStats.zoneCount, zoneStats.sweptZoneCount, - zoneStats.collectedCompartmentCount, zoneStats.compartmentCount, - zoneStats.sweptCompartmentCount, - double(preBytes) / bytesPerMiB, - counts[STAT_NEW_CHUNK] - counts[STAT_DESTROY_CHUNK], - counts[STAT_NEW_CHUNK] + counts[STAT_DESTROY_CHUNK]); + snprintf(buffer, sizeof(buffer), + "Zones: %d of %d (-%d); Compartments: %d of %d (-%d); HeapSize: %.3f MiB; "\ + "HeapChange (abs): %+d (%d); ", + zoneStats.collectedZoneCount, zoneStats.zoneCount, zoneStats.sweptZoneCount, + zoneStats.collectedCompartmentCount, zoneStats.compartmentCount, + zoneStats.sweptCompartmentCount, + double(preBytes) / bytesPerMiB, + counts[STAT_NEW_CHUNK] - counts[STAT_DESTROY_CHUNK], + counts[STAT_NEW_CHUNK] + counts[STAT_DESTROY_CHUNK]); if (!fragments.append(DuplicateString(buffer))) return UniqueChars(nullptr); MOZ_ASSERT_IF(counts[STAT_ARENA_RELOCATED], gckind == GC_SHRINK); if (gckind == GC_SHRINK) { - JS_snprintf(buffer, sizeof(buffer), - "Kind: %s; Relocated: %.3f MiB; ", - ExplainInvocationKind(gckind), - double(ArenaSize * counts[STAT_ARENA_RELOCATED]) / bytesPerMiB); + snprintf(buffer, sizeof(buffer), + "Kind: %s; Relocated: %.3f MiB; ", + ExplainInvocationKind(gckind), + double(ArenaSize * counts[STAT_ARENA_RELOCATED]) / bytesPerMiB); if (!fragments.append(DuplicateString(buffer))) return UniqueChars(nullptr); } @@ -425,13 +425,13 @@ Statistics::formatCompactSlicePhaseTimes(const PhaseTimeTable phaseTimes) const int64_t ownTime = phaseTimes[dagSlot][phase]; int64_t childTime = SumChildTimes(dagSlot, phase, phaseTimes); if (ownTime > MaxUnaccountedTimeUS) { - JS_snprintf(buffer, sizeof(buffer), "%s: %.3fms", phases[phase].name, t(ownTime)); + snprintf(buffer, sizeof(buffer), "%s: %.3fms", phases[phase].name, t(ownTime)); if (!fragments.append(DuplicateString(buffer))) return UniqueChars(nullptr); if (childTime && (ownTime - childTime) > MaxUnaccountedTimeUS) { MOZ_ASSERT(level < 3); - JS_snprintf(buffer, sizeof(buffer), "%s: %.3fms", "Other", t(ownTime - childTime)); + snprintf(buffer, sizeof(buffer), "%s: %.3fms", "Other", t(ownTime - childTime)); if (!fragments.append(DuplicateString(buffer))) return UniqueChars(nullptr); } @@ -492,22 +492,22 @@ Statistics::formatDetailedDescription() "; char buffer[1024]; memset(buffer, 0, sizeof(buffer)); - JS_snprintf(buffer, sizeof(buffer), format, - ExplainInvocationKind(gckind), - ExplainReason(slices[0].reason), - nonincrementalReason_ ? "no - " : "yes", - nonincrementalReason_ ? nonincrementalReason_ : "", - zoneStats.collectedZoneCount, zoneStats.zoneCount, zoneStats.sweptZoneCount, - zoneStats.collectedCompartmentCount, zoneStats.compartmentCount, - zoneStats.sweptCompartmentCount, - counts[STAT_MINOR_GC], - counts[STAT_STOREBUFFER_OVERFLOW], - mmu20 * 100., mmu50 * 100., - t(sccTotal), t(sccLongest), - double(preBytes) / bytesPerMiB, - counts[STAT_NEW_CHUNK] - counts[STAT_DESTROY_CHUNK], counts[STAT_NEW_CHUNK] + - counts[STAT_DESTROY_CHUNK], - double(ArenaSize * counts[STAT_ARENA_RELOCATED]) / bytesPerMiB); + snprintf(buffer, sizeof(buffer), format, + ExplainInvocationKind(gckind), + ExplainReason(slices[0].reason), + nonincrementalReason_ ? "no - " : "yes", + nonincrementalReason_ ? nonincrementalReason_ : "", + zoneStats.collectedZoneCount, zoneStats.zoneCount, zoneStats.sweptZoneCount, + zoneStats.collectedCompartmentCount, zoneStats.compartmentCount, + zoneStats.sweptCompartmentCount, + counts[STAT_MINOR_GC], + counts[STAT_STOREBUFFER_OVERFLOW], + mmu20 * 100., mmu50 * 100., + t(sccTotal), t(sccLongest), + double(preBytes) / bytesPerMiB, + counts[STAT_NEW_CHUNK] - counts[STAT_DESTROY_CHUNK], counts[STAT_NEW_CHUNK] + + counts[STAT_DESTROY_CHUNK], + double(ArenaSize * counts[STAT_ARENA_RELOCATED]) / bytesPerMiB); return DuplicateString(buffer); } @@ -528,12 +528,12 @@ Statistics::formatDetailedSliceDescription(unsigned i, const SliceData& slice) "; char buffer[1024]; memset(buffer, 0, sizeof(buffer)); - JS_snprintf(buffer, sizeof(buffer), format, i, - ExplainReason(slice.reason), - slice.resetReason ? "yes - " : "no", slice.resetReason ? slice.resetReason : "", - gc::StateName(slice.initialState), gc::StateName(slice.finalState), - uint64_t(slice.endFaults - slice.startFaults), - t(slice.duration()), budgetDescription, t(slice.start - slices[0].start)); + snprintf(buffer, sizeof(buffer), format, i, + ExplainReason(slice.reason), + slice.resetReason ? "yes - " : "no", slice.resetReason ? slice.resetReason : "", + gc::StateName(slice.initialState), gc::StateName(slice.finalState), + uint64_t(slice.endFaults - slice.startFaults), + t(slice.duration()), budgetDescription, t(slice.start - slices[0].start)); return DuplicateString(buffer); } @@ -555,15 +555,15 @@ Statistics::formatDetailedPhaseTimes(const PhaseTimeTable phaseTimes) int64_t ownTime = phaseTimes[dagSlot][phase]; int64_t childTime = SumChildTimes(dagSlot, phase, phaseTimes); if (ownTime > 0) { - JS_snprintf(buffer, sizeof(buffer), " %s%s: %.3fms\n", - LevelToIndent[level], phases[phase].name, t(ownTime)); + snprintf(buffer, sizeof(buffer), " %s%s: %.3fms\n", + LevelToIndent[level], phases[phase].name, t(ownTime)); if (!fragments.append(DuplicateString(buffer))) return UniqueChars(nullptr); if (childTime && (ownTime - childTime) > MaxUnaccountedChildTimeUS) { MOZ_ASSERT(level < 3); - JS_snprintf(buffer, sizeof(buffer), " %s%s: %.3fms\n", - LevelToIndent[level + 1], "Other", t(ownTime - childTime)); + snprintf(buffer, sizeof(buffer), " %s%s: %.3fms\n", + LevelToIndent[level + 1], "Other", t(ownTime - childTime)); if (!fragments.append(DuplicateString(buffer))) return UniqueChars(nullptr); } @@ -586,7 +586,7 @@ Statistics::formatDetailedTotals() "; char buffer[1024]; memset(buffer, 0, sizeof(buffer)); - JS_snprintf(buffer, sizeof(buffer), format, t(total), t(longest)); + snprintf(buffer, sizeof(buffer), format, t(total), t(longest)); return DuplicateString(buffer); } @@ -657,23 +657,23 @@ Statistics::formatJsonDescription(uint64_t timestamp) "\"removed_chunks\":%d,"; char buffer[1024]; memset(buffer, 0, sizeof(buffer)); - JS_snprintf(buffer, sizeof(buffer), format, - (unsigned long long)timestamp, - longest / 1000, longest % 1000, - total / 1000, total % 1000, - zoneStats.collectedZoneCount, - zoneStats.zoneCount, - zoneStats.compartmentCount, - counts[STAT_MINOR_GC], - counts[STAT_STOREBUFFER_OVERFLOW], - int(mmu20 * 100), - int(mmu50 * 100), - sccTotal / 1000, sccTotal % 1000, - sccLongest / 1000, sccLongest % 1000, - nonincrementalReason_ ? nonincrementalReason_ : "none", - unsigned(preBytes / 1024 / 1024), - counts[STAT_NEW_CHUNK], - counts[STAT_DESTROY_CHUNK]); + snprintf(buffer, sizeof(buffer), format, + (unsigned long long)timestamp, + longest / 1000, longest % 1000, + total / 1000, total % 1000, + zoneStats.collectedZoneCount, + zoneStats.zoneCount, + zoneStats.compartmentCount, + counts[STAT_MINOR_GC], + counts[STAT_STOREBUFFER_OVERFLOW], + int(mmu20 * 100), + int(mmu50 * 100), + sccTotal / 1000, sccTotal % 1000, + sccLongest / 1000, sccLongest % 1000, + nonincrementalReason_ ? nonincrementalReason_ : "none", + unsigned(preBytes / 1024 / 1024), + counts[STAT_NEW_CHUNK], + counts[STAT_DESTROY_CHUNK]); return DuplicateString(buffer); } @@ -699,17 +699,17 @@ Statistics::formatJsonSliceDescription(unsigned i, const SliceData& slice) "\"end_timestamp\":%llu,"; char buffer[1024]; memset(buffer, 0, sizeof(buffer)); - JS_snprintf(buffer, sizeof(buffer), format, - i, - duration / 1000, duration % 1000, - when / 1000, when % 1000, - ExplainReason(slice.reason), - gc::StateName(slice.initialState), - gc::StateName(slice.finalState), - budgetDescription, - pageFaults, - slice.start, - slice.end); + snprintf(buffer, sizeof(buffer), format, + i, + duration / 1000, duration % 1000, + when / 1000, when % 1000, + ExplainReason(slice.reason), + gc::StateName(slice.initialState), + gc::StateName(slice.finalState), + budgetDescription, + pageFaults, + slice.start, + slice.end); return DuplicateString(buffer); } @@ -740,8 +740,8 @@ Statistics::formatJsonPhaseTimes(const PhaseTimeTable phaseTimes) UniqueChars name = FilterJsonKey(phases[phase].name); int64_t ownTime = phaseTimes[dagSlot][phase]; - JS_snprintf(buffer, sizeof(buffer), "\"%s\":%llu.%03llu", - name.get(), ownTime / 1000, ownTime % 1000); + snprintf(buffer, sizeof(buffer), "\"%s\":%" PRId64 ".%03" PRId64, + name.get(), ownTime / 1000, ownTime % 1000); if (!fragments.append(DuplicateString(buffer))) return UniqueChars(nullptr); diff --git a/js/src/gc/Tracer.cpp b/js/src/gc/Tracer.cpp index 21d19e28743a..8507d100d547 100644 --- a/js/src/gc/Tracer.cpp +++ b/js/src/gc/Tracer.cpp @@ -96,10 +96,10 @@ JS::CallbackTracer::getTracingEdgeName(char* buffer, size_t bufferSize) return; } if (contextIndex_ != InvalidIndex) { - JS_snprintf(buffer, bufferSize, "%s[%lu]", contextName_, contextIndex_); + snprintf(buffer, bufferSize, "%s[%" PRIuSIZE "]", contextName_, contextIndex_); return; } - JS_snprintf(buffer, bufferSize, "%s", contextName_); + snprintf(buffer, bufferSize, "%s", contextName_); } @@ -375,9 +375,9 @@ JS_GetTraceThingInfo(char* buf, size_t bufsize, JSTracer* trc, void* thing, PutEscapedString(buf, bufsize, fun->displayAtom(), 0); } } else if (obj->getClass()->flags & JSCLASS_HAS_PRIVATE) { - JS_snprintf(buf, bufsize, " %p", obj->as().getPrivate()); + snprintf(buf, bufsize, " %p", obj->as().getPrivate()); } else { - JS_snprintf(buf, bufsize, " "); + snprintf(buf, bufsize, " "); } break; } @@ -385,7 +385,7 @@ JS_GetTraceThingInfo(char* buf, size_t bufsize, JSTracer* trc, void* thing, case JS::TraceKind::Script: { JSScript* script = static_cast(thing); - JS_snprintf(buf, bufsize, " %s:%" PRIuSIZE, script->filename(), script->lineno()); + snprintf(buf, bufsize, " %s:%" PRIuSIZE, script->filename(), script->lineno()); break; } @@ -399,7 +399,7 @@ JS_GetTraceThingInfo(char* buf, size_t bufsize, JSTracer* trc, void* thing, bool willFit = str->length() + strlen(" ") + CountDecimalDigits(str->length()) < bufsize; - n = JS_snprintf(buf, bufsize, " ", + n = snprintf(buf, bufsize, " ", str->length(), willFit ? "" : " (truncated)"); buf += n; @@ -407,7 +407,7 @@ JS_GetTraceThingInfo(char* buf, size_t bufsize, JSTracer* trc, void* thing, PutEscapedString(buf, bufsize, &str->asLinear(), 0); } else { - JS_snprintf(buf, bufsize, "", str->length()); + snprintf(buf, bufsize, "", str->length()); } break; } @@ -421,10 +421,10 @@ JS_GetTraceThingInfo(char* buf, size_t bufsize, JSTracer* trc, void* thing, bufsize--; PutEscapedString(buf, bufsize, &desc->asLinear(), 0); } else { - JS_snprintf(buf, bufsize, ""); + snprintf(buf, bufsize, ""); } } else { - JS_snprintf(buf, bufsize, ""); + snprintf(buf, bufsize, ""); } break; } diff --git a/js/src/gc/Verifier.cpp b/js/src/gc/Verifier.cpp index 2bf4e2a03759..ffc0028b3734 100644 --- a/js/src/gc/Verifier.cpp +++ b/js/src/gc/Verifier.cpp @@ -306,7 +306,7 @@ AssertMarkedOrAllocated(const EdgeValue& edge) return; char msgbuf[1024]; - JS_snprintf(msgbuf, sizeof(msgbuf), "[barrier verifier] Unmarked edge: %s", edge.label); + snprintf(msgbuf, sizeof(msgbuf), "[barrier verifier] Unmarked edge: %s", edge.label); MOZ_ReportAssertionFailure(msgbuf, __FILE__, __LINE__); MOZ_CRASH(); } diff --git a/js/src/jit/BaselineBailouts.cpp b/js/src/jit/BaselineBailouts.cpp index 8562954c501f..f7ce2a9e6af4 100644 --- a/js/src/jit/BaselineBailouts.cpp +++ b/js/src/jit/BaselineBailouts.cpp @@ -1152,13 +1152,13 @@ InitFromBailout(JSContext* cx, HandleScript caller, jsbytecode* callerPC, ReportOutOfMemory(cx); return false; } - JS_snprintf(buf, len, "%s %s %s on line %u of %s:%" PRIuSIZE, - BailoutKindString(bailoutKind), - resumeAfter ? "after" : "at", - CodeName[op], - PCToLineNumber(script, pc), - filename, - script->lineno()); + snprintf(buf, len, "%s %s %s on line %u of %s:%" PRIuSIZE, + BailoutKindString(bailoutKind), + resumeAfter ? "after" : "at", + CodeName[op], + PCToLineNumber(script, pc), + filename, + script->lineno()); cx->runtime()->spsProfiler.markEvent(buf); js_free(buf); } diff --git a/js/src/jit/CodeGenerator.cpp b/js/src/jit/CodeGenerator.cpp index 1077c2a35742..17b8aaa48990 100644 --- a/js/src/jit/CodeGenerator.cpp +++ b/js/src/jit/CodeGenerator.cpp @@ -4751,8 +4751,8 @@ CodeGenerator::maybeCreateScriptCounts() JSScript* innerScript = block->info().script(); description = (char*) js_calloc(200); if (description) { - JS_snprintf(description, 200, "%s:%" PRIuSIZE, - innerScript->filename(), innerScript->lineno()); + snprintf(description, 200, "%s:%" PRIuSIZE, + innerScript->filename(), innerScript->lineno()); } } } diff --git a/js/src/jit/JitSpewer.cpp b/js/src/jit/JitSpewer.cpp index 3f99b6a76391..a93e60210b56 100644 --- a/js/src/jit/JitSpewer.cpp +++ b/js/src/jit/JitSpewer.cpp @@ -178,14 +178,14 @@ IonSpewer::init() #endif size_t len; - len = JS_snprintf(jsonBuffer, bufferLength, JIT_SPEW_DIR "/ion%" PRIuSIZE ".json", pid); + len = snprintf(jsonBuffer, bufferLength, JIT_SPEW_DIR "/ion%" PRIuSIZE ".json", pid); if (bufferLength <= len) { fprintf(stderr, "Warning: IonSpewer::init: Cannot serialize file name."); return false; } jsonFilename = jsonBuffer; - len = JS_snprintf(c1Buffer, bufferLength, JIT_SPEW_DIR "/ion%" PRIuSIZE ".cfg", pid); + len = snprintf(c1Buffer, bufferLength, JIT_SPEW_DIR "/ion%" PRIuSIZE ".cfg", pid); if (bufferLength <= len) { fprintf(stderr, "Warning: IonSpewer::init: Cannot serialize file name."); return false; diff --git a/js/src/jit/JitcodeMap.cpp b/js/src/jit/JitcodeMap.cpp index 6bd412450474..5b37c68c7c2b 100644 --- a/js/src/jit/JitcodeMap.cpp +++ b/js/src/jit/JitcodeMap.cpp @@ -330,7 +330,7 @@ JitcodeGlobalEntry::createScriptString(JSContext* cx, JSScript* script, size_t* size_t linenoLength = 0; char linenoStr[15]; if (hasName || (script->functionNonDelazifying() || script->isForEval())) { - linenoLength = JS_snprintf(linenoStr, 15, "%" PRIuSIZE, script->lineno()); + linenoLength = snprintf(linenoStr, sizeof(linenoStr), "%" PRIuSIZE, script->lineno()); hasLineno = true; } diff --git a/js/src/jit/OptimizationTracking.cpp b/js/src/jit/OptimizationTracking.cpp index 286917ab9713..b611a813a2df 100644 --- a/js/src/jit/OptimizationTracking.cpp +++ b/js/src/jit/OptimizationTracking.cpp @@ -863,7 +863,7 @@ SpewConstructor(TypeSet::Type ty, JSFunction* constructor) if (constructor->displayAtom()) PutEscapedString(buf, 512, constructor->displayAtom(), 0); else - JS_snprintf(buf, mozilla::ArrayLength(buf), "??"); + snprintf(buf, mozilla::ArrayLength(buf), "??"); const char* filename; size_t lineno; @@ -1231,7 +1231,7 @@ IonTrackedOptimizationsTypeInfo::ForEachOpAdapter::readType(const IonTrackedType char locationBuf[20]; if (!name) { uintptr_t addr = JS_FUNC_TO_DATA_PTR(uintptr_t, fun->native()); - JS_snprintf(locationBuf, mozilla::ArrayLength(locationBuf), "%llx", addr); + snprintf(locationBuf, mozilla::ArrayLength(locationBuf), "%" PRIxPTR, addr); } op_.readType("native", name, name ? nullptr : locationBuf, Nothing()); return; @@ -1246,7 +1246,7 @@ IonTrackedOptimizationsTypeInfo::ForEachOpAdapter::readType(const IonTrackedType } const char* className = ty.objectKey()->clasp()->name; - JS_snprintf(buf, bufsize, "[object %s]", className); + snprintf(buf, bufsize, "[object %s]", className); if (tracked.hasAllocationSite()) { JSScript* script = tracked.script; diff --git a/js/src/jit/arm/Assembler-arm.cpp b/js/src/jit/arm/Assembler-arm.cpp index d5a23105b15d..69336be91f07 100644 --- a/js/src/jit/arm/Assembler-arm.cpp +++ b/js/src/jit/arm/Assembler-arm.cpp @@ -1495,7 +1495,7 @@ Assembler::spewBranch(Instruction* i, Label* target /* may be nullptr */) char labelBuf[128]; labelBuf[0] = 0; if (!target) - JS_snprintf(labelBuf, sizeof(labelBuf), " -> (link-time target)"); + snprintf(labelBuf, sizeof(labelBuf), " -> (link-time target)"); if (InstBranchImm::IsTHIS(*i)) { InstBranchImm* bimm = InstBranchImm::AsTHIS(*i); BOffImm destOff; @@ -1514,8 +1514,8 @@ Assembler::spewBranch(Instruction* i, Label* target /* may be nullptr */) ; buffer[i] = 0; if (target) { - JS_snprintf(labelBuf, sizeof(labelBuf), " -> %d%s", spewResolve(target), - !target->bound() ? "f" : ""); + snprintf(labelBuf, sizeof(labelBuf), " -> %d%s", spewResolve(target), + !target->bound() ? "f" : ""); target = nullptr; } } diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 231fa1f21fc8..92f8055d5ff2 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -122,7 +122,7 @@ JS::CallArgs::requireAtLeast(JSContext* cx, const char* fnname, unsigned require { if (length() < required) { char numArgsStr[40]; - JS_snprintf(numArgsStr, sizeof numArgsStr, "%u", required - 1); + snprintf(numArgsStr, sizeof(numArgsStr), "%u", required - 1); JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_MORE_ARGS_NEEDED, fnname, numArgsStr, required == 2 ? "" : "s"); return false; diff --git a/js/src/jscntxt.cpp b/js/src/jscntxt.cpp index 7d38dcedd6c8..eda7b69f036f 100644 --- a/js/src/jscntxt.cpp +++ b/js/src/jscntxt.cpp @@ -610,7 +610,7 @@ js::ExpandErrorArgumentsVA(ExclusiveContext* cx, JSErrorCallback callback, *messagep = cx->pod_malloc(nbytes); if (!*messagep) goto error; - JS_snprintf(*messagep, nbytes, defaultErrorMessage, errorNumber); + snprintf(*messagep, nbytes, defaultErrorMessage, errorNumber); } return true; @@ -786,7 +786,7 @@ js::ReportMissingArg(JSContext* cx, HandleValue v, unsigned arg) char argbuf[11]; UniqueChars bytes; - JS_snprintf(argbuf, sizeof argbuf, "%u", arg); + snprintf(argbuf, sizeof argbuf, "%u", arg); if (IsFunctionObject(v)) { RootedAtom name(cx, v.toObject().as().name()); bytes = DecompileValueGenerator(cx, JSDVG_SEARCH_STACK, v, name); @@ -1110,7 +1110,7 @@ void AutoEnterOOMUnsafeRegion::crash(const char* reason) { char msgbuf[1024]; - JS_snprintf(msgbuf, sizeof(msgbuf), "[unhandlable oom] %s", reason); + snprintf(msgbuf, sizeof(msgbuf), "[unhandlable oom] %s", reason); MOZ_ReportAssertionFailure(msgbuf, __FILE__, __LINE__); MOZ_CRASH(); } diff --git a/js/src/jsdate.cpp b/js/src/jsdate.cpp index ade54bd604ec..338f2b323505 100644 --- a/js/src/jsdate.cpp +++ b/js/src/jsdate.cpp @@ -2421,42 +2421,42 @@ static void print_gmt_string(char* buf, size_t size, double utctime) { MOZ_ASSERT(NumbersAreIdentical(TimeClip(utctime).toDouble(), utctime)); - JS_snprintf(buf, size, "%s, %.2d %s %.4d %.2d:%.2d:%.2d GMT", - days[int(WeekDay(utctime))], - int(DateFromTime(utctime)), - months[int(MonthFromTime(utctime))], - int(YearFromTime(utctime)), - int(HourFromTime(utctime)), - int(MinFromTime(utctime)), - int(SecFromTime(utctime))); + snprintf(buf, size, "%s, %.2d %s %.4d %.2d:%.2d:%.2d GMT", + days[int(WeekDay(utctime))], + int(DateFromTime(utctime)), + months[int(MonthFromTime(utctime))], + int(YearFromTime(utctime)), + int(HourFromTime(utctime)), + int(MinFromTime(utctime)), + int(SecFromTime(utctime))); } static void print_iso_string(char* buf, size_t size, double utctime) { MOZ_ASSERT(NumbersAreIdentical(TimeClip(utctime).toDouble(), utctime)); - JS_snprintf(buf, size, "%.4d-%.2d-%.2dT%.2d:%.2d:%.2d.%.3dZ", - int(YearFromTime(utctime)), - int(MonthFromTime(utctime)) + 1, - int(DateFromTime(utctime)), - int(HourFromTime(utctime)), - int(MinFromTime(utctime)), - int(SecFromTime(utctime)), - int(msFromTime(utctime))); + snprintf(buf, size, "%.4d-%.2d-%.2dT%.2d:%.2d:%.2d.%.3dZ", + int(YearFromTime(utctime)), + int(MonthFromTime(utctime)) + 1, + int(DateFromTime(utctime)), + int(HourFromTime(utctime)), + int(MinFromTime(utctime)), + int(SecFromTime(utctime)), + int(msFromTime(utctime))); } static void print_iso_extended_string(char* buf, size_t size, double utctime) { MOZ_ASSERT(NumbersAreIdentical(TimeClip(utctime).toDouble(), utctime)); - JS_snprintf(buf, size, "%+.6d-%.2d-%.2dT%.2d:%.2d:%.2d.%.3dZ", - int(YearFromTime(utctime)), - int(MonthFromTime(utctime)) + 1, - int(DateFromTime(utctime)), - int(HourFromTime(utctime)), - int(MinFromTime(utctime)), - int(SecFromTime(utctime)), - int(msFromTime(utctime))); + snprintf(buf, size, "%+.6d-%.2d-%.2dT%.2d:%.2d:%.2d.%.3dZ", + int(YearFromTime(utctime)), + int(MonthFromTime(utctime)) + 1, + int(DateFromTime(utctime)), + int(HourFromTime(utctime)), + int(MinFromTime(utctime)), + int(SecFromTime(utctime)), + int(msFromTime(utctime))); } /* ES5 B.2.6. */ @@ -2467,7 +2467,7 @@ date_toGMTString_impl(JSContext* cx, const CallArgs& args) char buf[100]; if (!IsFinite(utctime)) - JS_snprintf(buf, sizeof buf, js_NaN_date_str); + snprintf(buf, sizeof buf, js_NaN_date_str); else print_gmt_string(buf, sizeof buf, utctime); @@ -2592,7 +2592,7 @@ date_format(JSContext* cx, double date, formatspec format, MutableHandleValue rv PRMJTime split; if (!IsFinite(date)) { - JS_snprintf(buf, sizeof buf, js_NaN_date_str); + snprintf(buf, sizeof buf, js_NaN_date_str); } else { MOZ_ASSERT(NumbersAreIdentical(TimeClip(date).toDouble(), date)); @@ -2653,38 +2653,38 @@ date_format(JSContext* cx, double date, formatspec format, MutableHandleValue rv * requires a PRMJTime... which only has 16-bit years. Sub-ECMA. */ /* Tue Oct 31 2000 09:41:40 GMT-0800 (PST) */ - JS_snprintf(buf, sizeof buf, - "%s %s %.2d %.4d %.2d:%.2d:%.2d GMT%+.4d%s%s", - days[int(WeekDay(local))], - months[int(MonthFromTime(local))], - int(DateFromTime(local)), - int(YearFromTime(local)), - int(HourFromTime(local)), - int(MinFromTime(local)), - int(SecFromTime(local)), - offset, - usetz ? " " : "", - usetz ? tzbuf : ""); + snprintf(buf, sizeof buf, + "%s %s %.2d %.4d %.2d:%.2d:%.2d GMT%+.4d%s%s", + days[int(WeekDay(local))], + months[int(MonthFromTime(local))], + int(DateFromTime(local)), + int(YearFromTime(local)), + int(HourFromTime(local)), + int(MinFromTime(local)), + int(SecFromTime(local)), + offset, + usetz ? " " : "", + usetz ? tzbuf : ""); break; case FORMATSPEC_DATE: /* Tue Oct 31 2000 */ - JS_snprintf(buf, sizeof buf, - "%s %s %.2d %.4d", - days[int(WeekDay(local))], - months[int(MonthFromTime(local))], - int(DateFromTime(local)), - int(YearFromTime(local))); + snprintf(buf, sizeof buf, + "%s %s %.2d %.4d", + days[int(WeekDay(local))], + months[int(MonthFromTime(local))], + int(DateFromTime(local)), + int(YearFromTime(local))); break; case FORMATSPEC_TIME: /* 09:41:40 GMT-0800 (PST) */ - JS_snprintf(buf, sizeof buf, - "%.2d:%.2d:%.2d GMT%+.4d%s%s", - int(HourFromTime(local)), - int(MinFromTime(local)), - int(SecFromTime(local)), - offset, - usetz ? " " : "", - usetz ? tzbuf : ""); + snprintf(buf, sizeof buf, + "%.2d:%.2d:%.2d GMT%+.4d%s%s", + int(HourFromTime(local)), + int(MinFromTime(local)), + int(SecFromTime(local)), + offset, + usetz ? " " : "", + usetz ? tzbuf : ""); break; } } @@ -2703,7 +2703,7 @@ ToLocaleFormatHelper(JSContext* cx, HandleObject obj, const char* format, Mutabl char buf[100]; if (!IsFinite(utctime)) { - JS_snprintf(buf, sizeof buf, js_NaN_date_str); + snprintf(buf, sizeof buf, js_NaN_date_str); } else { int result_len; double local = LocalTime(utctime); @@ -2728,8 +2728,8 @@ ToLocaleFormatHelper(JSContext* cx, HandleObject obj, const char* format, Mutabl isdigit(buf[2]) && isdigit(buf[3]))) { double localtime = obj->as().cachedLocalTime(); int year = IsNaN(localtime) ? 0 : (int) YearFromTime(localtime); - JS_snprintf(buf + (result_len - 2), (sizeof buf) - (result_len - 2), - "%d", year); + snprintf(buf + (result_len - 2), (sizeof buf) - (result_len - 2), + "%d", year); } } diff --git a/js/src/jsdtoa.cpp b/js/src/jsdtoa.cpp index ab3cd0a917f3..6d0d950b474e 100644 --- a/js/src/jsdtoa.cpp +++ b/js/src/jsdtoa.cpp @@ -177,7 +177,7 @@ js_dtostr(DtoaState* state, char* buffer, size_t bufferSize, JSDToStrMode mode, numBegin[0] = numBegin[1]; numBegin[1] = '.'; } - JS_snprintf(numEnd, bufferSize - (numEnd - buffer), "e%+d", decPt-1); + snprintf(numEnd, bufferSize - (numEnd - buffer), "e%+d", decPt-1); } else if (decPt != nDigits) { /* Some kind of a fraction in fixed notation */ MOZ_ASSERT(decPt <= nDigits); diff --git a/js/src/jsexn.cpp b/js/src/jsexn.cpp index 97f1b206a938..4b71e5119096 100644 --- a/js/src/jsexn.cpp +++ b/js/src/jsexn.cpp @@ -741,12 +741,12 @@ ErrorReport::ReportAddonExceptionToTelementry(JSContext* cx) filename = "FILE_NOT_FOUND"; } char histogramKey[64]; - JS_snprintf(histogramKey, sizeof(histogramKey), - "%s %s %s %u", - addonIdChars.get(), - funname, - filename, - (reportp ? reportp->lineno : 0) ); + snprintf(histogramKey, sizeof(histogramKey), + "%s %s %s %u", + addonIdChars.get(), + funname, + filename, + (reportp ? reportp->lineno : 0) ); cx->runtime()->addTelemetry(JS_TELEMETRY_ADDON_EXCEPTIONS, 1, histogramKey); } diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index 7163a528cef1..615532d30d0d 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -2914,11 +2914,11 @@ int SliceBudget::describe(char* buffer, size_t maxlen) const { if (isUnlimited()) - return JS_snprintf(buffer, maxlen, "unlimited"); + return snprintf(buffer, maxlen, "unlimited"); else if (isWorkBudget()) - return JS_snprintf(buffer, maxlen, "work(%" PRId64 ")", workBudget.budget); + return snprintf(buffer, maxlen, "work(%" PRId64 ")", workBudget.budget); else - return JS_snprintf(buffer, maxlen, "%" PRId64 "ms", timeBudget.budget); + return snprintf(buffer, maxlen, "%" PRId64 "ms", timeBudget.budget); } bool diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp index e44a67a1dd96..6ce28cbaa198 100644 --- a/js/src/jsobj.cpp +++ b/js/src/jsobj.cpp @@ -3276,20 +3276,20 @@ GetObjectSlotNameFunctor::operator()(JS::CallbackTracer* trc, char* buf, size_t } if (slotname) - JS_snprintf(buf, bufsize, pattern, slotname); + snprintf(buf, bufsize, pattern, slotname); else - JS_snprintf(buf, bufsize, "**UNKNOWN SLOT %" PRIu32 "**", slot); + snprintf(buf, bufsize, "**UNKNOWN SLOT %" PRIu32 "**", slot); } while (false); } else { jsid propid = shape->propid(); if (JSID_IS_INT(propid)) { - JS_snprintf(buf, bufsize, "%" PRId32 "", JSID_TO_INT(propid)); + snprintf(buf, bufsize, "%" PRId32, JSID_TO_INT(propid)); } else if (JSID_IS_ATOM(propid)) { PutEscapedString(buf, bufsize, JSID_TO_ATOM(propid), 0); } else if (JSID_IS_SYMBOL(propid)) { - JS_snprintf(buf, bufsize, "**SYMBOL KEY**"); + snprintf(buf, bufsize, "**SYMBOL KEY**"); } else { - JS_snprintf(buf, bufsize, "**FINALIZED ATOM KEY**"); + snprintf(buf, bufsize, "**FINALIZED ATOM KEY**"); } } } diff --git a/js/src/jsopcode.cpp b/js/src/jsopcode.cpp index a62748e37348..bcb1798a8ba4 100644 --- a/js/src/jsopcode.cpp +++ b/js/src/jsopcode.cpp @@ -842,8 +842,8 @@ js::Disassemble1(JSContext* cx, HandleScript script, jsbytecode* pc, JSOp op = (JSOp)*pc; if (op >= JSOP_LIMIT) { char numBuf1[12], numBuf2[12]; - JS_snprintf(numBuf1, sizeof numBuf1, "%d", op); - JS_snprintf(numBuf2, sizeof numBuf2, "%d", JSOP_LIMIT); + snprintf(numBuf1, sizeof numBuf1, "%d", op); + snprintf(numBuf2, sizeof numBuf2, "%d", JSOP_LIMIT); JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_BYTECODE_TOO_BIG, numBuf1, numBuf2); return 0; @@ -1016,7 +1016,7 @@ js::Disassemble1(JSContext* cx, HandleScript script, jsbytecode* pc, default: { char numBuf[12]; - JS_snprintf(numBuf, sizeof numBuf, "%x", cs->format); + snprintf(numBuf, sizeof numBuf, "%x", cs->format); JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_UNKNOWN_FORMAT, numBuf); return 0; diff --git a/js/src/jsprf.cpp b/js/src/jsprf.cpp index 750cbbd71a7e..81bafb8c6150 100644 --- a/js/src/jsprf.cpp +++ b/js/src/jsprf.cpp @@ -969,72 +969,6 @@ JS_vsmprintf(const char* fmt, va_list ap) return ss.base; } -/* - * Stuff routine that discards overflow data - */ -static bool -LimitStuff(SprintfState* ss, const char* sp, size_t len) -{ - size_t limit = ss->maxlen - (ss->cur - ss->base); - - if (len > limit) - len = limit; - while (len) { - --len; - *ss->cur++ = *sp++; - } - return true; -} - -/* - * sprintf into a fixed size buffer. Make sure there is a NUL at the end - * when finished. - */ -JS_PUBLIC_API(uint32_t) -JS_snprintf(char* out, uint32_t outlen, const char* fmt, ...) -{ - va_list ap; - int rv; - - MOZ_ASSERT(outlen > 0); - if (outlen == 0) - return 0; - - va_start(ap, fmt); - rv = JS_vsnprintf(out, outlen, fmt, ap); - va_end(ap); - return rv; -} - -JS_PUBLIC_API(uint32_t) -JS_vsnprintf(char* out, uint32_t outlen, const char* fmt, va_list ap) -{ - SprintfState ss; - - if (outlen == 0) - return 0; - - ss.stuff = LimitStuff; - ss.base = out; - ss.cur = out; - ss.maxlen = outlen; - (void) dosprintf(&ss, fmt, ap); - - uint32_t charsWritten = ss.cur - ss.base; - MOZ_RELEASE_ASSERT(charsWritten > 0); - - // If we didn't append a null then we must have hit the buffer limit. Write - // a null terminator now and return a value indicating that we failed. - if (ss.cur[-1] != '\0') { - ss.cur[-1] = '\0'; - return outlen; - } - - // Success: return the number of character written excluding the null - // terminator. - return charsWritten - 1; -} - JS_PUBLIC_API(char*) JS_sprintf_append(char* last, const char* fmt, ...) { diff --git a/js/src/jsprf.h b/js/src/jsprf.h index 4c3ffde822d4..3bdbe638472c 100644 --- a/js/src/jsprf.h +++ b/js/src/jsprf.h @@ -32,13 +32,6 @@ #include "jstypes.h" -/* -** sprintf into a fixed size buffer. Guarantees that a NUL is at the end -** of the buffer. The return value is the length of the written output, -** NOT including the NUL, which is guaranteed less than "outlen" on success. -*/ -extern JS_PUBLIC_API(uint32_t) JS_snprintf(char* out, uint32_t outlen, const char* fmt, ...); - /* ** sprintf into a malloc'd buffer. Return a pointer to the malloc'd ** buffer on success, nullptr on failure. Call "JS_smprintf_free" to release @@ -63,7 +56,6 @@ extern JS_PUBLIC_API(char*) JS_sprintf_append(char* last, const char* fmt, ...); /* ** va_list forms of the above. */ -extern JS_PUBLIC_API(uint32_t) JS_vsnprintf(char* out, uint32_t outlen, const char* fmt, va_list ap); extern JS_PUBLIC_API(char*) JS_vsmprintf(const char* fmt, va_list ap); extern JS_PUBLIC_API(char*) JS_vsprintf_append(char* last, const char* fmt, va_list ap); diff --git a/js/src/jsscript.cpp b/js/src/jsscript.cpp index ac1f8ee14e1c..b23a8b1b8bc9 100644 --- a/js/src/jsscript.cpp +++ b/js/src/jsscript.cpp @@ -2312,7 +2312,7 @@ FormatIntroducedFilename(ExclusiveContext* cx, const char* filename, unsigned li // and wants us to use a special free function.) char linenoBuf[15]; size_t filenameLen = strlen(filename); - size_t linenoLen = JS_snprintf(linenoBuf, 15, "%u", lineno); + size_t linenoLen = snprintf(linenoBuf, sizeof(linenoBuf), "%u", lineno); size_t introducerLen = strlen(introducer); size_t len = filenameLen + 6 /* == strlen(" line ") */ + @@ -2325,8 +2325,8 @@ FormatIntroducedFilename(ExclusiveContext* cx, const char* filename, unsigned li ReportOutOfMemory(cx); return nullptr; } - mozilla::DebugOnly checkLen = JS_snprintf(formatted, len, "%s line %s > %s", - filename, linenoBuf, introducer); + mozilla::DebugOnly checkLen = snprintf(formatted, len, "%s line %s > %s", + filename, linenoBuf, introducer); MOZ_ASSERT(checkLen == len - 1); return formatted; diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index ad54d800d56d..d8f33d99f95a 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -1508,9 +1508,9 @@ Evaluate(JSContext* cx, unsigned argc, Value* vp) if (loadBytecode && assertEqBytecode) { if (saveLength != loadLength) { char loadLengthStr[16]; - JS_snprintf(loadLengthStr, sizeof(loadLengthStr), "%" PRIu32, loadLength); + snprintf(loadLengthStr, sizeof(loadLengthStr), "%" PRIu32, loadLength); char saveLengthStr[16]; - JS_snprintf(saveLengthStr, sizeof(saveLengthStr), "%" PRIu32, saveLength); + snprintf(saveLengthStr, sizeof(saveLengthStr), "%" PRIu32, saveLength); JS_ReportErrorNumber(cx, my_GetErrorMessage, nullptr, JSSMSG_CACHE_EQ_SIZE_FAILED, loadLengthStr, saveLengthStr); diff --git a/js/src/vm/CharacterEncoding.cpp b/js/src/vm/CharacterEncoding.cpp index 67f81589c4d6..c3fc8e89e98e 100644 --- a/js/src/vm/CharacterEncoding.cpp +++ b/js/src/vm/CharacterEncoding.cpp @@ -226,7 +226,7 @@ static void ReportInvalidCharacter(JSContext* cx, uint32_t offset) { char buffer[10]; - JS_snprintf(buffer, 10, "%u", offset); + snprintf(buffer, 10, "%u", offset); JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR, GetErrorMessage, nullptr, JSMSG_MALFORMED_UTF8_CHAR, buffer); } @@ -241,7 +241,7 @@ static void ReportTooBigCharacter(JSContext* cx, uint32_t v) { char buffer[10]; - JS_snprintf(buffer, 10, "0x%x", v + 0x10000); + snprintf(buffer, 10, "0x%x", v + 0x10000); JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR, GetErrorMessage, nullptr, JSMSG_UTF8_CHAR_TOO_LARGE, buffer); } diff --git a/js/src/vm/CodeCoverage.cpp b/js/src/vm/CodeCoverage.cpp index 676fea6d6fc9..088a7a307edc 100644 --- a/js/src/vm/CodeCoverage.cpp +++ b/js/src/vm/CodeCoverage.cpp @@ -570,9 +570,9 @@ LCovRuntime::fillWithFilename(char *name, size_t length) static mozilla::Atomic globalRuntimeId(0); size_t rid = globalRuntimeId++; - size_t len = JS_snprintf(name, length, "%s/%" PRId64 "-%" PRIuSIZE "-%" PRIuSIZE ".info", - outDir, timestamp, pid_, rid); - if (length <= len) { + int len = snprintf(name, length, "%s/%" PRId64 "-%" PRIuSIZE "-%" PRIuSIZE ".info", + outDir, timestamp, pid_, rid); + if (length != size_t(len)) { fprintf(stderr, "Warning: LCovRuntime::init: Cannot serialize file name."); return false; } diff --git a/js/src/vm/Debugger.cpp b/js/src/vm/Debugger.cpp index 1e68aba40d82..3963a9573112 100644 --- a/js/src/vm/Debugger.cpp +++ b/js/src/vm/Debugger.cpp @@ -348,7 +348,7 @@ class MOZ_RAII js::EnterDebuggeeNoExecute } const char* filename = script->filename() ? script->filename() : "(none)"; char linenoStr[15]; - JS_snprintf(linenoStr, sizeof(linenoStr), "%" PRIuSIZE, script->lineno()); + snprintf(linenoStr, sizeof(linenoStr), "%" PRIuSIZE, script->lineno()); unsigned flags = warning ? JSREPORT_WARNING : JSREPORT_ERROR; return JS_ReportErrorFlagsAndNumber(cx, flags, GetErrorMessage, nullptr, JSMSG_DEBUGGEE_WOULD_RUN, diff --git a/js/src/vm/Interpreter.cpp b/js/src/vm/Interpreter.cpp index 09afb290980a..49246a1fd9b3 100644 --- a/js/src/vm/Interpreter.cpp +++ b/js/src/vm/Interpreter.cpp @@ -4034,7 +4034,7 @@ END_CASE(JSOP_IS_CONSTRUCTING) DEFAULT() { char numBuf[12]; - JS_snprintf(numBuf, sizeof numBuf, "%d", *REGS.pc); + snprintf(numBuf, sizeof numBuf, "%d", *REGS.pc); JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_BAD_BYTECODE, numBuf); goto error; diff --git a/js/src/vm/JSONParser.cpp b/js/src/vm/JSONParser.cpp index 2bc07fadb909..54c4c963068f 100644 --- a/js/src/vm/JSONParser.cpp +++ b/js/src/vm/JSONParser.cpp @@ -90,9 +90,9 @@ JSONParser::error(const char* msg) const size_t MaxWidth = sizeof("4294967295"); char columnNumber[MaxWidth]; - JS_snprintf(columnNumber, sizeof columnNumber, "%" PRIu32, column); + snprintf(columnNumber, sizeof columnNumber, "%" PRIu32, column); char lineNumber[MaxWidth]; - JS_snprintf(lineNumber, sizeof lineNumber, "%" PRIu32, line); + snprintf(lineNumber, sizeof lineNumber, "%" PRIu32, line); JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_JSON_BAD_PARSE, msg, lineNumber, columnNumber); diff --git a/js/src/vm/Printer.cpp b/js/src/vm/Printer.cpp index 8c574407aaad..d72fbfebf9d1 100644 --- a/js/src/vm/Printer.cpp +++ b/js/src/vm/Printer.cpp @@ -208,7 +208,7 @@ Sprinter::vprintf(const char* fmt, va_list ap) do { va_list aq; va_copy(aq, ap); - int i = JS_vsnprintf(base + offset, size - offset, fmt, aq); + int i = vsnprintf(base + offset, size - offset, fmt, aq); va_end(aq); if (i > -1 && (size_t) i < size - offset) { offset += i; diff --git a/js/src/vm/SPSProfiler.cpp b/js/src/vm/SPSProfiler.cpp index 173d11c5c2ec..6b162439bdf1 100644 --- a/js/src/vm/SPSProfiler.cpp +++ b/js/src/vm/SPSProfiler.cpp @@ -347,9 +347,9 @@ SPSProfiler::allocProfileString(JSScript* script, JSFunction* maybeFun) js_free(cstr); return nullptr; } - ret = JS_snprintf(cstr, len + 1, "%s (%s:%" PRIu64 ")", atomStr.get(), filename, lineno); + ret = snprintf(cstr, len + 1, "%s (%s:%" PRIu64 ")", atomStr.get(), filename, lineno); } else { - ret = JS_snprintf(cstr, len + 1, "%s:%" PRIu64, filename, lineno); + ret = snprintf(cstr, len + 1, "%s:%" PRIu64, filename, lineno); } MOZ_ASSERT(ret == len, "Computed length should match actual length!"); diff --git a/js/src/vm/TraceLogging.cpp b/js/src/vm/TraceLogging.cpp index 3c3e501dcbbc..311641db4d08 100644 --- a/js/src/vm/TraceLogging.cpp +++ b/js/src/vm/TraceLogging.cpp @@ -363,7 +363,7 @@ TraceLoggerThread::getOrCreateEventPayload(const char* text) if (!str) return nullptr; - DebugOnly ret = JS_snprintf(str, len + 1, "%s", text); + DebugOnly ret = snprintf(str, len + 1, "%s", text); MOZ_ASSERT(ret == len); MOZ_ASSERT(strlen(str) == len); @@ -431,7 +431,7 @@ TraceLoggerThread::getOrCreateEventPayload(TraceLoggerTextId type, const char* f return nullptr; DebugOnly ret = - JS_snprintf(str, len + 1, "script %s:%" PRIuSIZE ":%" PRIuSIZE, filename, lineno, colno); + snprintf(str, len + 1, "script %s:%" PRIuSIZE ":%" PRIuSIZE, filename, lineno, colno); MOZ_ASSERT(ret == len); MOZ_ASSERT(strlen(str) == len); diff --git a/js/src/vm/TypeInference.cpp b/js/src/vm/TypeInference.cpp index 4c7116fe2942..a2513c1dc60c 100644 --- a/js/src/vm/TypeInference.cpp +++ b/js/src/vm/TypeInference.cpp @@ -205,9 +205,9 @@ TypeSet::TypeString(TypeSet::Type type) which = (which + 1) & 3; if (type.isSingleton()) - JS_snprintf(bufs[which], 40, "<0x%p>", (void*) type.singletonNoBarrier()); + snprintf(bufs[which], 40, "<0x%p>", (void*) type.singletonNoBarrier()); else - JS_snprintf(bufs[which], 40, "[0x%p]", (void*) type.groupNoBarrier()); + snprintf(bufs[which], 40, "[0x%p]", (void*) type.groupNoBarrier()); return bufs[which]; } @@ -232,6 +232,26 @@ js::InferSpew(SpewChannel channel, const char* fmt, ...) va_end(ap); } +MOZ_NORETURN MOZ_COLD static void +TypeFailure(JSContext* cx, const char* fmt, ...) +{ + char msgbuf[1024]; /* Larger error messages will be truncated */ + char errbuf[1024]; + + va_list ap; + va_start(ap, fmt); + vsnprintf(errbuf, sizeof(errbuf), fmt, ap); + va_end(ap); + + snprintf(msgbuf, sizeof(msgbuf), "[infer failure] %s", errbuf); + + /* Dump type state, even if INFERFLAGS is unset. */ + PrintTypes(cx, cx->compartment(), true); + + MOZ_ReportAssertionFailure(msgbuf, __FILE__, __LINE__); + MOZ_CRASH(); +} + bool js::ObjectGroupHasProperty(JSContext* cx, ObjectGroup* group, jsid id, const Value& value) { @@ -286,25 +306,6 @@ js::ObjectGroupHasProperty(JSContext* cx, ObjectGroup* group, jsid id, const Val #endif -void -js::TypeFailure(JSContext* cx, const char* fmt, ...) -{ - char msgbuf[1024]; /* Larger error messages will be truncated */ - char errbuf[1024]; - - va_list ap; - va_start(ap, fmt); - JS_vsnprintf(errbuf, sizeof(errbuf), fmt, ap); - va_end(ap); - - JS_snprintf(msgbuf, sizeof(msgbuf), "[infer failure] %s", errbuf); - - /* Dump type state, even if INFERFLAGS is unset. */ - PrintTypes(cx, cx->compartment(), true); - - MOZ_ReportAssertionFailure(msgbuf, __FILE__, __LINE__); - MOZ_CRASH(); -} ///////////////////////////////////////////////////////////////////// // TypeSet diff --git a/js/src/vm/TypeInference.h b/js/src/vm/TypeInference.h index bc8ff0cbd0a3..d20340aa6252 100644 --- a/js/src/vm/TypeInference.h +++ b/js/src/vm/TypeInference.h @@ -1310,9 +1310,6 @@ inline void InferSpew(SpewChannel which, const char* fmt, ...) {} #endif -/* Print a warning, dump state and abort the program. */ -MOZ_NORETURN MOZ_COLD void TypeFailure(JSContext* cx, const char* fmt, ...); - // Prints type information for a context if spew is enabled or force is set. void PrintTypes(JSContext* cx, JSCompartment* comp, bool force); diff --git a/js/xpconnect/src/XPCConvert.cpp b/js/xpconnect/src/XPCConvert.cpp index 313f55de1c73..f649aa898c39 100644 --- a/js/xpconnect/src/XPCConvert.cpp +++ b/js/xpconnect/src/XPCConvert.cpp @@ -361,7 +361,7 @@ CheckChar16InCharRange(char16_t c) /* U+0080/U+0100 - U+FFFF data lost. */ static const size_t MSG_BUF_SIZE = 64; char msg[MSG_BUF_SIZE]; - JS_snprintf(msg, MSG_BUF_SIZE, "char16_t out of char range; high bits of data lost: 0x%x", c); + snprintf(msg, MSG_BUF_SIZE, "char16_t out of char range; high bits of data lost: 0x%x", int(c)); NS_WARNING(msg); return false; } diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSRuntime.cpp index a50386bcc8f0..0b77250c3412 100644 --- a/js/xpconnect/src/XPCJSRuntime.cpp +++ b/js/xpconnect/src/XPCJSRuntime.cpp @@ -3689,8 +3689,7 @@ XPCJSRuntime::DescribeCustomObjects(JSObject* obj, const js::Class* clasp, return false; } - JS_snprintf(name, sizeof(name), "JS Object (%s - %s)", - clasp->name, si->GetJSClass()->name); + snprintf(name, sizeof(name), "JS Object (%s - %s)", clasp->name, si->GetJSClass()->name); return true; } diff --git a/js/xpconnect/src/XPCWrappedJS.cpp b/js/xpconnect/src/XPCWrappedJS.cpp index dee277dc31f3..302068c77156 100644 --- a/js/xpconnect/src/XPCWrappedJS.cpp +++ b/js/xpconnect/src/XPCWrappedJS.cpp @@ -103,10 +103,9 @@ NS_CYCLE_COLLECTION_CLASSNAME(nsXPCWrappedJS)::Traverse if (cb.WantDebugInfo()) { char name[72]; if (tmp->GetClass()) - JS_snprintf(name, sizeof(name), "nsXPCWrappedJS (%s)", - tmp->GetClass()->GetInterfaceName()); + snprintf(name, sizeof(name), "nsXPCWrappedJS (%s)", tmp->GetClass()->GetInterfaceName()); else - JS_snprintf(name, sizeof(name), "nsXPCWrappedJS"); + snprintf(name, sizeof(name), "nsXPCWrappedJS"); cb.DescribeRefCountedNode(refcnt, name); } else { NS_IMPL_CYCLE_COLLECTION_DESCRIBE(nsXPCWrappedJS, refcnt) diff --git a/js/xpconnect/src/XPCWrappedNative.cpp b/js/xpconnect/src/XPCWrappedNative.cpp index 2a35835a8ff1..4cdd3846e0ed 100644 --- a/js/xpconnect/src/XPCWrappedNative.cpp +++ b/js/xpconnect/src/XPCWrappedNative.cpp @@ -51,10 +51,9 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(XPCWrappedNative) char name[72]; XPCNativeScriptableInfo* si = tmp->GetScriptableInfo(); if (si) - JS_snprintf(name, sizeof(name), "XPCWrappedNative (%s)", - si->GetJSClass()->name); + snprintf(name, sizeof(name), "XPCWrappedNative (%s)", si->GetJSClass()->name); else - JS_snprintf(name, sizeof(name), "XPCWrappedNative"); + snprintf(name, sizeof(name), "XPCWrappedNative"); cb.DescribeRefCountedNode(tmp->mRefCnt.get(), name); } else {