Backed out changeset cda26e6b7fcc (bug 1349719) for bustage.
authorRyan VanderMeulen <ryanvm@gmail.com>
Thu, 06 Apr 2017 07:33:46 -0400
changeset 379462 db49c7b778064599f028d5b3a96cda1deb257e5d
parent 379461 3fb6a3a1295455248faa371fc75ebfa1d9c277e3
child 379463 390df62a9c2ee8f4fc4b168a81e61bf23a435a0c
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1349719
milestone53.0
backs outcda26e6b7fcc916889b3a1eeb8a206db934b91a2
Backed out changeset cda26e6b7fcc (bug 1349719) for bustage.
xpcom/string/nsTSubstring.cpp
--- a/xpcom/string/nsTSubstring.cpp
+++ b/xpcom/string/nsTSubstring.cpp
@@ -5,21 +5,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/CheckedInt.h"
 #include "mozilla/double-conversion.h"
 #include "mozilla/MemoryReporting.h"
 
 using double_conversion::DoubleToStringConverter;
 
-const nsTSubstring_CharT::size_type nsTSubstring_CharT::kMaxCapacity =
-    (nsTSubstring_CharT::size_type(-1) /
-        2 - sizeof(nsStringBuffer)) /
-    sizeof(nsTSubstring_CharT::char_type) - 2;
-
 #ifdef XPCOM_STRING_CONSTRUCTOR_OUT_OF_LINE
 nsTSubstring_CharT::nsTSubstring_CharT(char_type* aData, size_type aLength,
                                        uint32_t aFlags)
   : mData(aData),
     mLength(aLength),
     mFlags(aFlags)
 {
   if (aFlags & F_OWNED) {
@@ -56,18 +51,23 @@ nsTSubstring_CharT::MutatePrep(size_type
 
   size_type curCapacity = Capacity();
 
   // If |aCapacity > kMaxCapacity|, then our doubling algorithm may not be
   // able to allocate it.  Just bail out in cases like that.  We don't want
   // to be allocating 2GB+ strings anyway.
   static_assert((sizeof(nsStringBuffer) & 0x1) == 0,
                 "bad size for nsStringBuffer");
-  if (!CheckCapacity(aCapacity)) {
-      return false;
+  const size_type kMaxCapacity =
+    (size_type(-1) / 2 - sizeof(nsStringBuffer)) / sizeof(char_type) - 2;
+  if (aCapacity > kMaxCapacity) {
+    // Also assert for |aCapacity| equal to |size_type(-1)|, since we used to
+    // use that value to flag immutability.
+    NS_ASSERTION(aCapacity != size_type(-1), "Bogus capacity");
+    return false;
   }
 
   // |curCapacity == 0| means that the buffer is immutable or 0-sized, so we
   // need to allocate a new buffer. We cannot use the existing buffer even
   // though it might be large enough.
 
   if (curCapacity != 0) {
     if (aCapacity <= curCapacity) {
@@ -505,18 +505,16 @@ nsTSubstring_CharT::Adopt(char_type* aDa
 {
   if (aData) {
     ::ReleaseData(mData, mFlags);
 
     if (aLength == size_type(-1)) {
       aLength = char_traits::length(aData);
     }
 
-    MOZ_RELEASE_ASSERT(CheckCapacity(aLength), "adopting a too-long string");
-
     mData = aData;
     mLength = aLength;
     SetDataFlags(F_TERMINATED | F_OWNED);
 
     STRING_STAT_INCREMENT(Adopt);
     // Treat this as construction of a "StringAdopt" object for leak
     // tracking purposes.
     MOZ_LOG_CTOR(mData, "StringAdopt", 1);