Bug 1338574 - Part 7: Use MOZ_CRASH_UNSAFE_PRINTF in XPCOM. r=froydnj

--HG--
extra : rebase_source : 472e0aa151692bda55b7bf3f8d98cf7bb4488481
This commit is contained in:
Emanuel Hoogeveen 2017-02-21 18:02:03 +01:00
parent d8ab2e5bec
commit 23c68657e0
2 changed files with 6 additions and 18 deletions

View File

@ -629,13 +629,8 @@ RegisterStaticAtoms(const nsStaticAtom* aAtoms, uint32_t aAtomCount)
if (!atom->IsStaticAtom()) {
nsAutoCString name;
atom->ToUTF8String(name);
static char sCrashReason[1024];
SprintfLiteral(sCrashReason,
"static atom registration for %s should be pushed back",
name.get());
MOZ_CRASH_ANNOTATE(sCrashReason);
MOZ_REALLY_CRASH();
MOZ_CRASH_UNSAFE_PRINTF(
"Static atom registration for %s should be pushed back", name.get());
}
} else {
atom = new StaticAtom(stringBuffer, stringLen, hash);

View File

@ -9,6 +9,7 @@
#include "nsXPCOM.h"
#include "nsDebug.h"
#include "mozilla/CheckedInt.h"
#include "mozilla/IntegerPrintfMacros.h"
nsTArrayHeader nsTArrayHeader::sEmptyHdr = { 0, 0, 0 };
@ -22,15 +23,7 @@ IsTwiceTheRequiredBytesRepresentableAsUint32(size_t aCapacity, size_t aElemSize)
MOZ_NORETURN MOZ_COLD void
InvalidArrayIndex_CRASH(size_t aIndex, size_t aLength)
{
const size_t CAPACITY = 512;
// Leak the buffer on the heap to make sure that it lives long enough, as
// MOZ_CRASH_ANNOTATE expects the pointer passed to it to live to the end of
// the program.
auto* buffer = new char[CAPACITY];
snprintf(buffer, CAPACITY,
"ElementAt(aIndex = %llu, aLength = %llu)",
(long long unsigned) aIndex,
(long long unsigned) aLength);
MOZ_CRASH_ANNOTATE(buffer);
MOZ_REALLY_CRASH();
MOZ_CRASH_UNSAFE_PRINTF(
"ElementAt(aIndex = %" PRIu64 ", aLength = %" PRIu64 ")",
static_cast<uint64_t>(aIndex), static_cast<uint64_t>(aLength));
}