Backed out changeset 9216e8942ed6 (bug 1484987) for build bustages at builds/worker/workspace/build/src/xpcom/io/nsStorageStream.cpp on a CLOSED TREE
authorAndreea Pavel <apavel@mozilla.com>
Wed, 29 Aug 2018 08:36:19 +0300
changeset 482062 14e5c98875ec7b56d847f74f4eb1658683126310
parent 482061 9216e8942ed6d31b68411623420e45f3ca964adf
child 482063 4e4416a2bd7f5096b8101796d85d748a94c1bb0f
push id232
push userfmarier@mozilla.com
push dateWed, 05 Sep 2018 20:45:54 +0000
bugs1484987
milestone63.0a1
backs out9216e8942ed6d31b68411623420e45f3ca964adf
Backed out changeset 9216e8942ed6 (bug 1484987) for build bustages at builds/worker/workspace/build/src/xpcom/io/nsStorageStream.cpp on a CLOSED TREE
xpcom/io/Base64.cpp
xpcom/io/nsStorageStream.cpp
--- a/xpcom/io/Base64.cpp
+++ b/xpcom/io/Base64.cpp
@@ -386,24 +386,26 @@ Base64EncodeHelper(const T& aBinary, T& 
 
   if (aBinary.IsEmpty()) {
     aBase64.Truncate();
     return NS_OK;
   }
 
   uint32_t base64Len = ((aBinary.Length() + 2) / 3) * 4;
 
-  nsresult rv;
-  auto handle = aBase64.BulkWrite(base64Len, 0, false, rv);
-  if (NS_FAILED(rv)) {
-    return rv;
+  // Add one byte for null termination.
+  if (!aBase64.SetCapacity(base64Len + 1, fallible)) {
+    return NS_ERROR_OUT_OF_MEMORY;
   }
 
-  Encode(aBinary.BeginReading(), aBinary.Length(), handle.Elements());
-  handle.Finish(base64Len, false);
+  typename T::char_type* base64 = aBase64.BeginWriting();
+  Encode(aBinary.BeginReading(), aBinary.Length(), base64);
+  base64[base64Len] = '\0';
+
+  aBase64.SetLength(base64Len);
   return NS_OK;
 }
 
 nsresult
 Base64Encode(const nsACString& aBinary, nsACString& aBase64)
 {
   return Base64EncodeHelper(aBinary, aBase64);
 }
@@ -568,29 +570,30 @@ Base64DecodeString(const T& aBase64, T& 
   // Don't decode the empty string
   if (aBase64.IsEmpty()) {
     aBinary.Truncate();
     return NS_OK;
   }
 
   uint32_t binaryLen = ((aBase64.Length() * 3) / 4);
 
-  nsresult rv;
-  auto handle = aBinary.BulkWrite(binaryLen, 0, false, rv);
-  if(NS_FAILED(rv)) {
+  // Add one byte for null termination.
+  if (!aBinary.SetCapacity(binaryLen + 1, fallible)) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
+
+  typename T::char_type* binary = aBinary.BeginWriting();
+  nsresult rv = Base64DecodeHelper(aBase64.BeginReading(), aBase64.Length(),
+                                   binary, &binaryLen);
+  if (NS_FAILED(rv)) {
+    aBinary.Truncate();
     return rv;
   }
 
-  rv = Base64DecodeHelper(aBase64.BeginReading(), aBase64.Length(),
-                          handle.Elements(), &binaryLen);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  handle.Finish(binaryLen, true);
+  aBinary.SetLength(binaryLen);
   return NS_OK;
 }
 
 nsresult
 Base64Decode(const nsACString& aBase64, nsACString& aBinary)
 {
   return Base64DecodeString(aBase64, aBinary);
 }
--- a/xpcom/io/nsStorageStream.cpp
+++ b/xpcom/io/nsStorageStream.cpp
@@ -580,25 +580,23 @@ nsStorageInputStream::Serialize(InputStr
   int64_t offset;
   mozilla::DebugOnly<nsresult> rv = Tell(&offset);
   MOZ_ASSERT(NS_SUCCEEDED(rv));
 
   uint64_t remaining;
   rv = Available(&remaining);
   MOZ_ASSERT(NS_SUCCEEDED(rv));
 
-  auto handle = combined.BulkWrite(remaining, 0, false, rv);
-  MOZ_ASSERT(NS_SUCCEEDED(rv));
-
+  combined.SetCapacity(remaining);
   uint32_t numRead = 0;
 
-  rv = Read(handle.Elements(), remaining, &numRead);
+  rv = Read(combined.BeginWriting(), remaining, &numRead);
   MOZ_ASSERT(NS_SUCCEEDED(rv));
   MOZ_ASSERT(numRead == remaining);
-  handle.Finish(numRead, false);
+  combined.SetLength(numRead);
 
   rv = Seek(NS_SEEK_SET, offset);
   MOZ_ASSERT(NS_SUCCEEDED(rv));
 
   StringInputStreamParams params;
   params.data() = combined;
   aParams = params;
 }