Bug 793253. Infallible TArrays should really be infallible. r=jlebar
authorBoris Zbarsky <bzbarsky@mit.edu>
Sat, 22 Sep 2012 22:04:54 -0400
changeset 107836 415f11a2bb1ae06e7bf912c48a4e7df43ca52bcf
parent 107835 8e4eaae128c431f7b63ef14369243498dc945915
child 107837 5dc812bc69dc9c18067ac9ed9ceb85884afba0d8
push id15233
push userbzbarsky@mozilla.com
push dateSun, 23 Sep 2012 02:05:20 +0000
treeherdermozilla-inbound@415f11a2bb1a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlebar
bugs793253
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 793253. Infallible TArrays should really be infallible. r=jlebar
xpcom/glue/nsTArray-inl.h
xpcom/glue/nsTArray.h
--- a/xpcom/glue/nsTArray-inl.h
+++ b/xpcom/glue/nsTArray-inl.h
@@ -104,17 +104,17 @@ nsTArray_base<Alloc>::EnsureCapacity(siz
     return true;
 
   // If the requested memory allocation exceeds size_type(-1)/2, then
   // our doubling algorithm may not be able to allocate it.
   // Additionally we couldn't fit in the Header::mCapacity
   // member. Just bail out in cases like that.  We don't want to be
   // allocating 2 GB+ arrays anyway.
   if ((uint64_t)capacity * elemSize > size_type(-1)/2) {
-    NS_ERROR("Attempting to allocate excessively large array");
+    Alloc::SizeTooBig();
     return false;
   }
 
   if (mHdr == EmptyHdr()) {
     // Malloc() new data
     Header *header = static_cast<Header*>
                      (Alloc::Malloc(sizeof(Header) + capacity * elemSize));
     if (!header)
--- a/xpcom/glue/nsTArray.h
+++ b/xpcom/glue/nsTArray.h
@@ -30,44 +30,53 @@
 
 //
 // nsTArray*Allocators must all use the same |free()|, to allow
 // swapping between fallible and infallible variants.  (NS_Free() and
 // moz_free() end up calling the same underlying free()).
 //
 
 #if defined(MOZALLOC_HAVE_XMALLOC)
+#include "mozilla/mozalloc_abort.h"
+
 struct nsTArrayFallibleAllocator
 {
   static void* Malloc(size_t size) {
     return moz_malloc(size);
   }
 
   static void* Realloc(void* ptr, size_t size) {
     return moz_realloc(ptr, size);
   }
 
   static void Free(void* ptr) {
     moz_free(ptr);
   }
+
+  static void SizeTooBig() {
+  }
 };
 
 struct nsTArrayInfallibleAllocator
 {
   static void* Malloc(size_t size) {
     return moz_xmalloc(size);
   }
 
   static void* Realloc(void* ptr, size_t size) {
     return moz_xrealloc(ptr, size);
   }
 
   static void Free(void* ptr) {
     moz_free(ptr);
   }
+
+  static void SizeTooBig() {
+    mozalloc_abort("Trying to allocate an infallible array that's too big");
+  }
 };
 
 #else
 
 #include <stdlib.h>
 struct nsTArrayFallibleAllocator
 {
   static void* Malloc(size_t size) {
@@ -76,16 +85,19 @@ struct nsTArrayFallibleAllocator
 
   static void* Realloc(void* ptr, size_t size) {
     return realloc(ptr, size);
   }
 
   static void Free(void* ptr) {
     free(ptr);
   }
+
+  static void SizeTooBig() {
+  }
 };
 
 #endif
 
 #if defined(MOZALLOC_HAVE_XMALLOC)
 struct nsTArrayDefaultAllocator : public nsTArrayInfallibleAllocator { };
 #else
 struct nsTArrayDefaultAllocator : public nsTArrayFallibleAllocator { };