Bug 935376 - Back out 2e6063aa9b77 (bug 328755) on suspicion of causing a crash in ntdll
authorMatt Brubeck <mbrubeck@mozilla.com>
Tue, 05 Nov 2013 21:12:56 -0800
changeset 169221 9ba3faa35c96c789fed68bf344244f41a5c9e708
parent 169220 3689b4820015e7dba8ef6611474d6959c14b039a
child 169248 bf1211047db43402b813074a8c49478314c5689d
child 171513 25c2d493929a8b6dc9cb23805b6d3e9e120c3b4d
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs935376, 328755
milestone28.0a1
first release with
nightly linux32
9ba3faa35c96 / 28.0a1 / 20131106030200 / files
nightly linux64
9ba3faa35c96 / 28.0a1 / 20131106030200 / files
nightly mac
9ba3faa35c96 / 28.0a1 / 20131106030200 / files
nightly win32
9ba3faa35c96 / 28.0a1 / 20131106030200 / files
nightly win64
9ba3faa35c96 / 28.0a1 / 20131106030200 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 935376 - Back out 2e6063aa9b77 (bug 328755) on suspicion of causing a crash in ntdll
xpcom/io/Base64.cpp
xpcom/io/nsEscape.cpp
xpcom/string/public/nsCharTraits.h
xpcom/string/src/nsSubstring.cpp
xpcom/string/src/nsTSubstring.cpp
--- a/xpcom/io/Base64.cpp
+++ b/xpcom/io/Base64.cpp
@@ -203,20 +203,17 @@ EncodeInputStream(nsIInputStream *aInput
     if (!read)
       break;
   }
 
   // Finish encoding if anything is left
   if (state.charsOnStack)
     Encode(state.c, state.charsOnStack, state.buffer);
 
-  if (aDest.Length())
-    // May belong to an nsCString with an unallocated buffer, so only null
-    // terminate if there is a need to.
-    *aDest.EndWriting() = '\0';
+  *aDest.EndWriting() = '\0';
 
   return NS_OK;
 }
 
 } // namespace (anonymous)
 
 namespace mozilla {
 
--- a/xpcom/io/nsEscape.cpp
+++ b/xpcom/io/nsEscape.cpp
@@ -176,25 +176,17 @@ int32_t nsUnescapeCount(char * str)
             {
             	*dst = (*dst + UNHEX(*src));
             	src++;
             }
         	dst++;
         }
     }
 
-    /* The string may belong to a nsCString with an unallocated buffer.
-       In such a situation the buffer points to a const char, so attempting
-       to write to it will crash.  This can be avoided by only null-terminating
-       when needed.  The above while loop is safe as it won't iterate when this
-       occurs.
-     */
-    if (*dst) {
-        *dst = 0;
-    }
+    *dst = 0;
     return (int)(dst - str);
 
 } /* NET_UnEscapeCnt */
 
 
 char *
 nsEscapeHTML(const char * string)
 {
--- a/xpcom/string/public/nsCharTraits.h
+++ b/xpcom/string/public/nsCharTraits.h
@@ -95,17 +95,17 @@ template <class CharT> struct nsCharTrai
 
 template <>
 struct nsCharTraits<PRUnichar>
   {
     typedef PRUnichar char_type;
     typedef uint16_t  unsigned_char_type;
     typedef char      incompatible_char_type;
 
-    static char_type * const sEmptyBuffer;
+    static char_type *sEmptyBuffer;
 
     static
     void
     assign( char_type& lhs, char_type rhs )
       {
         lhs = rhs;
       }
 
@@ -321,17 +321,17 @@ struct nsCharTraits<PRUnichar>
 
 template <>
 struct nsCharTraits<char>
   {
     typedef char           char_type;
     typedef unsigned char  unsigned_char_type;
     typedef PRUnichar      incompatible_char_type;
 
-    static char_type *const sEmptyBuffer;
+    static char_type *sEmptyBuffer;
 
     static
     void
     assign( char_type& lhs, char_type rhs )
       {
         lhs = rhs;
       }
 
--- a/xpcom/string/src/nsSubstring.cpp
+++ b/xpcom/string/src/nsSubstring.cpp
@@ -24,22 +24,20 @@
 #include "prprf.h"
 #include "nsStaticAtom.h"
 #include "nsCOMPtr.h"
 
 using mozilla::Atomic;
 
 // ---------------------------------------------------------------------------
 
-static const PRUnichar gNullChar = 0;
+static PRUnichar gNullChar = 0;
 
-char* const      nsCharTraits<char>     ::sEmptyBuffer = 
-  (char*) const_cast<PRUnichar*>(&gNullChar);
-PRUnichar* const nsCharTraits<PRUnichar>::sEmptyBuffer = 
-  const_cast<PRUnichar*>(&gNullChar);
+char*      nsCharTraits<char>     ::sEmptyBuffer = (char*) &gNullChar;
+PRUnichar* nsCharTraits<PRUnichar>::sEmptyBuffer =         &gNullChar;
 
 // ---------------------------------------------------------------------------
 
 #ifdef ENABLE_STRING_STATS
 class nsStringStats
   {
     public:
       nsStringStats()
--- a/xpcom/string/src/nsTSubstring.cpp
+++ b/xpcom/string/src/nsTSubstring.cpp
@@ -297,17 +297,17 @@ nsTSubstring_CharT::Assign( const char_t
   {
     if (!Assign(data, length, fallible_t()))
       NS_RUNTIMEABORT("OOM");
   }
 
 bool
 nsTSubstring_CharT::Assign( const char_type* data, size_type length, const fallible_t& )
   {
-    if (!data || length == 0)
+    if (!data)
       {
         Truncate();
         return true;
       }
 
     if (length == size_type(-1))
       length = char_traits::length(data);