Bug 1338574 - Part 7: Use MOZ_CRASH_UNSAFE_PRINTF in XPCOM. r=froydnj, a=NPOTB
authorEmanuel Hoogeveen <emanuel.hoogeveen@gmail.com>
Tue, 21 Feb 2017 18:02:03 +0100
changeset 355808 1d14abf37cf8cac38763f79c70742fac5a0fbb16
parent 355807 697713a6841ca85e9daadf8bcbbe20585141ef8f
child 355809 5e85bc599d0c94f0ba792c9505081ba6486f7557
push id7088
push userryanvm@gmail.com
push dateThu, 11 May 2017 21:13:08 +0000
treeherdermozilla-esr52@5e85bc599d0c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj, NPOTB
bugs1338574
milestone52.1.2
Bug 1338574 - Part 7: Use MOZ_CRASH_UNSAFE_PRINTF in XPCOM. r=froydnj, a=NPOTB
xpcom/ds/nsAtomTable.cpp
xpcom/glue/nsTArray.cpp
--- a/xpcom/ds/nsAtomTable.cpp
+++ b/xpcom/ds/nsAtomTable.cpp
@@ -629,23 +629,18 @@ RegisterStaticAtoms(const nsStaticAtom* 
     if (atom) {
       // Disallow creating a dynamic atom, and then later, while the
       // dynamic atom is still alive, registering that same atom as a
       // static atom.  It causes subtle bugs, and we're programming in
       // C++ here, not Smalltalk.
       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);
       he->mAtom = atom;
     }
     *atomp = atom;
 
     if (!gStaticAtomTableSealed) {
--- a/xpcom/glue/nsTArray.cpp
+++ b/xpcom/glue/nsTArray.cpp
@@ -4,33 +4,26 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <string.h>
 #include "nsTArray.h"
 #include "nsXPCOM.h"
 #include "nsDebug.h"
 #include "mozilla/CheckedInt.h"
+#include "mozilla/IntegerPrintfMacros.h"
 
 nsTArrayHeader nsTArrayHeader::sEmptyHdr = { 0, 0, 0 };
 
 bool
 IsTwiceTheRequiredBytesRepresentableAsUint32(size_t aCapacity, size_t aElemSize)
 {
   using mozilla::CheckedUint32;
   return ((CheckedUint32(aCapacity) * aElemSize) * 2).isValid();
 }
 
 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.
-  char* 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));
 }