Bug 1330759 part 5. Back out the nsTSubstring changes we made in bug 1324430, because they can lead to non-null-terminated nsStrings. r=froydnj
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 18 Jan 2017 22:20:15 -0500
changeset 375092 1873ff6e9179711bd79ca1510383c2cdb20e00e5
parent 375091 22ae3a4fb412d9278eb472395fa96c82f68a4809
child 375093 5f327e934dfece65b00baf439dd1554f2ff0e990
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1330759, 1324430
milestone53.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 1330759 part 5. Back out the nsTSubstring changes we made in bug 1324430, because they can lead to non-null-terminated nsStrings. r=froydnj
xpcom/string/nsTSubstring.cpp
xpcom/string/nsTSubstring.h
--- a/xpcom/string/nsTSubstring.cpp
+++ b/xpcom/string/nsTSubstring.cpp
@@ -412,80 +412,61 @@ nsTSubstring_CharT::AssignLiteral(const 
   mData = const_cast<char_type*>(aData);
   mLength = aLength;
   SetDataFlags(F_TERMINATED | F_LITERAL);
 }
 
 void
 nsTSubstring_CharT::Assign(const self_type& aStr)
 {
-  if (!Assign(aStr, aStr.Length(), mozilla::fallible)) {
+  if (!Assign(aStr, mozilla::fallible)) {
     AllocFailed(aStr.Length());
   }
 }
 
 bool
 nsTSubstring_CharT::Assign(const self_type& aStr, const fallible_t& aFallible)
 {
-  return Assign(aStr, aStr.Length(), aFallible);
-}
-
-void
-nsTSubstring_CharT::Assign(const self_type& aStr, size_type aLength)
-{
-  if (!Assign(aStr, aLength, mozilla::fallible)) {
-    AllocFailed(aLength);
-  }
-}
-
-bool
-nsTSubstring_CharT::Assign(const self_type& aStr, size_type aLength,
-                           const fallible_t& aFallible)
-{
   // |aStr| could be sharable. We need to check its flags to know how to
   // deal with it.
 
   if (&aStr == this) {
     return true;
   }
 
-  if (aStr.Length() < aLength) {
-    aLength = aStr.Length();
-  }
-
-  if (!aLength) {
+  if (!aStr.mLength) {
     Truncate();
     mFlags |= aStr.mFlags & F_VOIDED;
     return true;
   }
 
   if (aStr.mFlags & F_SHARED) {
     // nice! we can avoid a string copy :-)
 
     // |aStr| should be null-terminated
     NS_ASSERTION(aStr.mFlags & F_TERMINATED, "shared, but not terminated");
 
     ::ReleaseData(mData, mFlags);
 
     mData = aStr.mData;
-    mLength = aLength;
+    mLength = aStr.mLength;
     SetDataFlags(F_TERMINATED | F_SHARED);
 
     // get an owning reference to the mData
     nsStringBuffer::FromData(mData)->AddRef();
     return true;
   } else if (aStr.mFlags & F_LITERAL) {
     MOZ_ASSERT(aStr.mFlags & F_TERMINATED, "Unterminated literal");
 
-    AssignLiteral(aStr.mData, aLength);
+    AssignLiteral(aStr.mData, aStr.mLength);
     return true;
   }
 
   // else, treat this like an ordinary assignment.
-  return Assign(aStr.Data(), aLength, aFallible);
+  return Assign(aStr.Data(), aStr.Length(), aFallible);
 }
 
 void
 nsTSubstring_CharT::Assign(const substring_tuple_type& aTuple)
 {
   if (!Assign(aTuple, mozilla::fallible)) {
     AllocFailed(aTuple.Length());
   }
--- a/xpcom/string/nsTSubstring.h
+++ b/xpcom/string/nsTSubstring.h
@@ -373,30 +373,16 @@ public:
 
   void NS_FASTCALL Assign(const self_type&);
   MOZ_MUST_USE bool NS_FASTCALL Assign(const self_type&, const fallible_t&);
 
   void NS_FASTCALL Assign(const substring_tuple_type&);
   MOZ_MUST_USE bool NS_FASTCALL Assign(const substring_tuple_type&,
                                        const fallible_t&);
 
-  // Assign at most aLength characters of aStr to this, fallibly.
-  // If aLength is more than the number of characters in aStr.Length(),
-  // only assign aStr.Length() characters.
-  //
-  // Using this method is functionally equivalent to:
-  //
-  //   str.Assign(other.BeginReading, other.Length(), fallible);
-  //
-  // but may enable string buffer sharing.
-  void NS_FASTCALL Assign(const self_type& aStr, size_type aLength);
-  MOZ_MUST_USE bool NS_FASTCALL Assign(const self_type& aStr,
-                                       size_type aLength,
-                                       const fallible_t&);
-
 #if defined(CharT_is_PRUnichar) && defined(MOZ_USE_CHAR16_WRAPPER)
   void Assign(char16ptr_t aData)
   {
     Assign(static_cast<const char16_t*>(aData));
   }
 
   void Assign(char16ptr_t aData, size_type aLength)
   {