Bug 1233234 - part 1 - use UniquePtr<T[]> instead of nsAutoArrayPtr<T> in openPrefFile; r=njn
authorNathan Froyd <froydnj@mozilla.com>
Sun, 06 Dec 2015 08:13:36 -0500
changeset 312361 ad982906992424a5a4ac1d21b47eea777a640e6f
parent 312360 df759fa9dcf53883fc9b8afe73d84ce827791d69
child 312362 cb6e7e36a32608178cab1824ca7d96ca064fdc9d
push id5703
push userraliiev@mozilla.com
push dateMon, 07 Mar 2016 14:18:41 +0000
treeherdermozilla-beta@31e373ad5b5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1233234
milestone46.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 1233234 - part 1 - use UniquePtr<T[]> instead of nsAutoArrayPtr<T> in openPrefFile; r=njn
modules/libpref/Preferences.cpp
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -985,33 +985,33 @@ static nsresult openPrefFile(nsIFile* aF
 
   int64_t fileSize64;
   rv = aFile->GetFileSize(&fileSize64);
   if (NS_FAILED(rv))
     return rv;
   NS_ENSURE_TRUE(fileSize64 <= UINT32_MAX, NS_ERROR_FILE_TOO_BIG);
 
   uint32_t fileSize = (uint32_t)fileSize64;
-  nsAutoArrayPtr<char> fileBuffer(new char[fileSize]);
+  auto fileBuffer = MakeUniqueFallible<char[]>(fileSize);
   if (fileBuffer == nullptr)
     return NS_ERROR_OUT_OF_MEMORY;
 
   PrefParseState ps;
   PREF_InitParseState(&ps, PREF_ReaderCallback, nullptr);
 
   // Read is not guaranteed to return a buf the size of fileSize,
   // but usually will.
   nsresult rv2 = NS_OK;
   uint32_t offset = 0;
   for (;;) {
     uint32_t amtRead = 0;
-    rv = inStr->Read((char*)fileBuffer, fileSize, &amtRead);
+    rv = inStr->Read(fileBuffer.get(), fileSize, &amtRead);
     if (NS_FAILED(rv) || amtRead == 0)
       break;
-    if (!PREF_ParseBuf(&ps, fileBuffer, amtRead))
+    if (!PREF_ParseBuf(&ps, fileBuffer.get(), amtRead))
       rv2 = NS_ERROR_FILE_CORRUPTED;
     offset += amtRead;
     if (offset == fileSize) {
       break;
     }
   }
 
   PREF_FinalizeParseState(&ps);