Bug 801483 - make nsBufferedInputStream::Init fallible. r=bsmith
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Tue, 16 Oct 2012 17:38:20 +0900
changeset 110527 6e0ef3f6629000fd55eedab049a75284f65a442e
parent 110526 c60f1eb791b3a29d219763d0cf93c7625b656521
child 110528 19132b752db10d7fe7aebe1f407e834aba814fda
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersbsmith
bugs801483
milestone19.0a1
Bug 801483 - make nsBufferedInputStream::Init fallible. r=bsmith
dom/devicestorage/nsDeviceStorage.cpp
layout/base/nsPresShell.cpp
netwerk/base/public/nsNetUtil.h
netwerk/base/src/nsBufferedStreams.cpp
netwerk/cache/nsDiskCacheDeviceSQL.cpp
--- a/dom/devicestorage/nsDeviceStorage.cpp
+++ b/dom/devicestorage/nsDeviceStorage.cpp
@@ -354,25 +354,21 @@ DeviceStorageFile::Write(nsIInputStream*
   nsCOMPtr<nsIOutputStream> outputStream;
   NS_NewLocalFileOutputStream(getter_AddRefs(outputStream), mFile);
 
   if (!outputStream) {
     return NS_ERROR_FAILURE;
   }
 
   nsCOMPtr<nsIOutputStream> bufferedOutputStream;
-  NS_NewBufferedOutputStream(getter_AddRefs(bufferedOutputStream),
-                             outputStream,
-                             4096*4);
+  rv = NS_NewBufferedOutputStream(getter_AddRefs(bufferedOutputStream),
+                                  outputStream,
+                                  4096*4);
+  NS_ENSURE_SUCCESS(rv, rv);
 
-  if (!bufferedOutputStream) {
-    return NS_ERROR_FAILURE;
-  }
-
-  rv = NS_OK;
   while (bufSize) {
     uint32_t wrote;
     rv = bufferedOutputStream->WriteFrom(aInputStream,
                                          static_cast<uint32_t>(NS_MIN<uint64_t>(bufSize, UINT32_MAX)),
                                          &wrote);
     if (NS_FAILED(rv)) {
       break;
     }
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -8111,16 +8111,17 @@ DumpToPNG(nsIPresShell* shell, nsAString
 
   nsCOMPtr<nsIOutputStream> outputStream;
   rv = NS_NewLocalFileOutputStream(getter_AddRefs(outputStream), file);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIOutputStream> bufferedOutputStream;
   rv = NS_NewBufferedOutputStream(getter_AddRefs(bufferedOutputStream),
                                   outputStream, length);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   uint32_t numWritten;
   rv = bufferedOutputStream->WriteFrom(encoder, length, &numWritten);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 #endif
--- a/netwerk/base/public/nsNetUtil.h
+++ b/netwerk/base/public/nsNetUtil.h
@@ -1028,17 +1028,17 @@ NS_BackgroundOutputStream(nsIOutputStrea
         if (NS_SUCCEEDED(rv))
             rv = inTransport->OpenOutputStream(nsITransport::OPEN_BLOCKING,
                                                segmentSize, segmentCount,
                                                result);
     }
     return rv;
 }
 
-inline nsresult
+MOZ_WARN_UNUSED_RESULT inline nsresult
 NS_NewBufferedInputStream(nsIInputStream **result,
                           nsIInputStream  *str,
                           uint32_t         bufferSize)
 {
     nsresult rv;
     nsCOMPtr<nsIBufferedInputStream> in =
         do_CreateInstance(NS_BUFFEREDINPUTSTREAM_CONTRACTID, &rv);
     if (NS_SUCCEEDED(rv)) {
--- a/netwerk/base/src/nsBufferedStreams.cpp
+++ b/netwerk/base/src/nsBufferedStreams.cpp
@@ -67,17 +67,18 @@ nsBufferedStream::Init(nsISupports* stre
 {
     NS_ASSERTION(stream, "need to supply a stream");
     NS_ASSERTION(mStream == nullptr, "already inited");
     mStream = stream;
     NS_IF_ADDREF(mStream);
     mBufferSize = bufferSize;
     mBufferStartOffset = 0;
     mCursor = 0;
-    mBuffer = new char[bufferSize];
+    const mozilla::fallible_t fallible = mozilla::fallible_t();
+    mBuffer = new (fallible) char[bufferSize];
     if (mBuffer == nullptr)
         return NS_ERROR_OUT_OF_MEMORY;
     return NS_OK;
 }
 
 nsresult
 nsBufferedStream::Close()
 {
--- a/netwerk/cache/nsDiskCacheDeviceSQL.cpp
+++ b/netwerk/cache/nsDiskCacheDeviceSQL.cpp
@@ -1739,19 +1739,19 @@ nsOfflineCacheDevice::OpenOutputStreamFo
   NS_ENSURE_TRUE(seekable, NS_ERROR_UNEXPECTED);
   if (offset != 0)
     seekable->Seek(nsISeekableStream::NS_SEEK_SET, offset);
 
   // truncate the file at the given offset
   seekable->SetEOF();
 
   nsCOMPtr<nsIOutputStream> bufferedOut;
-  NS_NewBufferedOutputStream(getter_AddRefs(bufferedOut), out, 16 * 1024);
-  if (!bufferedOut)
-    return NS_ERROR_UNEXPECTED;
+  nsresult rv =
+    NS_NewBufferedOutputStream(getter_AddRefs(bufferedOut), out, 16 * 1024);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   bufferedOut.swap(*result);
   return NS_OK;
 }
 
 nsresult
 nsOfflineCacheDevice::GetFileForEntry(nsCacheEntry *entry, nsIFile **result)
 {