Bug 804742 - EnsureStringLength doesn't work. f=Ms2ger, r=ehsan
authorSumedh Shekhar <sumedhhere@gmail.com>
Wed, 08 May 2013 00:52:52 +0900
changeset 131128 63b5d65eaedb126ccb3af849fededfce2e7d282f
parent 131127 9a86629a8fa2659178c3a2a150a15ce4088a8adf
child 131129 ac70913833fdc463785ee26bafd3087498d00975
push id24649
push userryanvm@gmail.com
push dateWed, 08 May 2013 02:10:32 +0000
treeherdermozilla-central@b980d32c366f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs804742
milestone23.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 804742 - EnsureStringLength doesn't work. f=Ms2ger, r=ehsan
content/base/src/nsDocumentEncoder.cpp
content/base/src/nsScriptLoader.cpp
content/xslt/src/base/txDouble.cpp
dom/indexedDB/IDBObjectStore.cpp
dom/plugins/base/nsPluginTags.cpp
layout/base/nsBidiPresUtils.cpp
netwerk/base/src/nsStandardURL.cpp
netwerk/cache/nsDiskCacheDeviceSQL.cpp
netwerk/streamconv/converters/nsDirIndexParser.cpp
parser/htmlparser/src/nsScannerString.cpp
widget/windows/nsIMM32Handler.cpp
xpcom/io/nsBinaryStream.cpp
xpcom/io/nsLocalFileWin.cpp
xpcom/io/nsNativeCharsetUtils.cpp
--- a/content/base/src/nsDocumentEncoder.cpp
+++ b/content/base/src/nsDocumentEncoder.cpp
@@ -544,17 +544,17 @@ ConvertAndWrite(const nsAString& aString
   int32_t unicodeLength = aString.Length();
   int32_t startLength = unicodeLength;
 
   rv = aEncoder->GetMaxLength(unicodeBuf, unicodeLength, &charLength);
   startCharLength = charLength;
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsAutoCString charXferString;
-  if (!EnsureStringLength(charXferString, charLength))
+  if (!charXferString.SetLength(charLength, fallible_t()))
     return NS_ERROR_OUT_OF_MEMORY;
 
   char* charXferBuf = charXferString.BeginWriting();
   nsresult convert_rv = NS_OK;
 
   do {
     unicodeLength = startLength;
     charLength = startCharLength;
--- a/content/base/src/nsScriptLoader.cpp
+++ b/content/base/src/nsScriptLoader.cpp
@@ -1057,17 +1057,17 @@ nsScriptLoader::ConvertToUTF16(nsIChanne
 
   int32_t unicodeLength = 0;
 
   nsresult rv =
     unicodeDecoder->GetMaxLength(reinterpret_cast<const char*>(aData),
                                  aLength, &unicodeLength);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  if (!EnsureStringLength(aString, unicodeLength)) {
+  if (!aString.SetLength(unicodeLength, fallible_t())) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   PRUnichar *ustr = aString.BeginWriting();
 
   rv = unicodeDecoder->Convert(reinterpret_cast<const char*>(aData),
                                (int32_t *) &aLength, ustr,
                                &unicodeLength);
--- a/content/xslt/src/base/txDouble.cpp
+++ b/content/xslt/src/base/txDouble.cpp
@@ -174,17 +174,17 @@ void txDouble::toString(double aValue, n
     else {
         // trailing zeros, total length given by intDigits
         length = intDigits;
     }
     if (aValue < 0)
         ++length;
     // grow the string
     uint32_t oldlength = aDest.Length();
-    if (!EnsureStringLength(aDest, oldlength + length))
+    if (!aDest.SetLength(oldlength + length, mozilla::fallible_t()))
         return; // out of memory
     nsAString::iterator dest;
     aDest.BeginWriting(dest).advance(int32_t(oldlength));
     if (aValue < 0) {
         *dest = '-'; ++dest;
     }
     int i;
     // leading zeros
--- a/dom/indexedDB/IDBObjectStore.cpp
+++ b/dom/indexedDB/IDBObjectStore.cpp
@@ -1296,17 +1296,17 @@ StructuredCloneReadString(JSStructuredCl
 {
   uint32_t length;
   if (!JS_ReadBytes(aReader, &length, sizeof(uint32_t))) {
     NS_WARNING("Failed to read length!");
     return false;
   }
   length = SwapBytes(length);
 
-  if (!EnsureStringLength(aString, length)) {
+  if (!aString.SetLength(length, mozilla::fallible_t())) {
     NS_WARNING("Out of memory?");
     return false;
   }
   char* buffer = aString.BeginWriting();
 
   if (!JS_ReadBytes(aReader, buffer, length)) {
     NS_WARNING("Failed to read type!");
     return false;
--- a/dom/plugins/base/nsPluginTags.cpp
+++ b/dom/plugins/base/nsPluginTags.cpp
@@ -211,17 +211,17 @@ static nsresult ConvertToUTF8(nsIUnicode
                               nsAFlatCString& aString)
 {
   int32_t numberOfBytes = aString.Length();
   int32_t outUnicodeLen;
   nsAutoString buffer;
   nsresult rv = aUnicodeDecoder->GetMaxLength(aString.get(), numberOfBytes,
                                               &outUnicodeLen);
   NS_ENSURE_SUCCESS(rv, rv);
-  if (!EnsureStringLength(buffer, outUnicodeLen))
+  if (!buffer.SetLength(outUnicodeLen, fallible_t()))
     return NS_ERROR_OUT_OF_MEMORY;
   rv = aUnicodeDecoder->Convert(aString.get(), &numberOfBytes,
                                 buffer.BeginWriting(), &outUnicodeLen);
   NS_ENSURE_SUCCESS(rv, rv);
   buffer.SetLength(outUnicodeLen);
   CopyUTF16toUTF8(buffer, aString);
   
   return NS_OK;
--- a/layout/base/nsBidiPresUtils.cpp
+++ b/layout/base/nsBidiPresUtils.cpp
@@ -2134,17 +2134,17 @@ void nsBidiPresUtils::CopyLogicalToVisua
                                           nsAString& aDest,
                                           nsBidiLevel aBaseDirection,
                                           bool aOverride)
 {
   aDest.SetLength(0);
   uint32_t srcLength = aSource.Length();
   if (srcLength == 0)
     return;
-  if (!EnsureStringLength(aDest, srcLength)) {
+  if (!aDest.SetLength(srcLength, fallible_t())) {
     return;
   }
   nsAString::const_iterator fromBegin, fromEnd;
   nsAString::iterator toBegin;
   aSource.BeginReading(fromBegin);
   aSource.EndReading(fromEnd);
   aDest.BeginWriting(toBegin);
 
--- a/netwerk/base/src/nsStandardURL.cpp
+++ b/netwerk/base/src/nsStandardURL.cpp
@@ -551,17 +551,17 @@ nsStandardURL::BuildNormalizedSpec(const
         else
             approxLen += mHost.mLen;
     }
 
     //
     // generate the normalized URL string
     //
     // approxLen should be correct or 1 high
-    if (!EnsureStringLength(mSpec, approxLen+1)) // buf needs a trailing '\0' below
+    if (!mSpec.SetLength(approxLen+1, mozilla::fallible_t())) // buf needs a trailing '\0' below
         return NS_ERROR_OUT_OF_MEMORY;
     char *buf;
     mSpec.BeginWriting(buf);
     uint32_t i = 0;
 
     if (mScheme.mLen > 0) {
         i = AppendSegmentToBuf(buf, i, spec, mScheme);
         net_ToLowerCase(buf + mScheme.mPos, mScheme.mLen);
--- a/netwerk/cache/nsDiskCacheDeviceSQL.cpp
+++ b/netwerk/cache/nsDiskCacheDeviceSQL.cpp
@@ -945,17 +945,17 @@ nsOfflineCacheDevice::UpdateEntry(nsCach
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = entry->SetMetaDataElement("security-info", info.get());
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   nsCString metaDataBuf;
   uint32_t mdSize = entry->MetaDataSize();
-  if (!EnsureStringLength(metaDataBuf, mdSize))
+  if (!metaDataBuf.SetLength(mdSize, fallible_t()))
     return NS_ERROR_OUT_OF_MEMORY;
   char *md = metaDataBuf.BeginWriting();
   entry->FlattenMetaData(md, mdSize);
 
   nsOfflineCacheRecord rec;
   rec.metaData = (const uint8_t *) md;
   rec.metaDataLen = mdSize;
   rec.dataSize = entry->DataSize();
--- a/netwerk/streamconv/converters/nsDirIndexParser.cpp
+++ b/netwerk/streamconv/converters/nsDirIndexParser.cpp
@@ -349,17 +349,17 @@ nsDirIndexParser::OnDataAvailable(nsIReq
                                   uint32_t aCount) {
   if (aCount < 1)
     return NS_OK;
   
   int32_t len = mBuf.Length();
   
   // Ensure that our mBuf has capacity to hold the data we're about to
   // read.
-  if (!EnsureStringLength(mBuf, len + aCount))
+  if (!mBuf.SetLength(len + aCount, fallible_t()))
     return NS_ERROR_OUT_OF_MEMORY;
 
   // Now read the data into our buffer.
   nsresult rv;
   uint32_t count;
   rv = aStream->Read(mBuf.BeginWriting() + len, aCount, &count);
   if (NS_FAILED(rv)) return rv;
 
--- a/parser/htmlparser/src/nsScannerString.cpp
+++ b/parser/htmlparser/src/nsScannerString.cpp
@@ -480,17 +480,17 @@ copy_multifragment_string( nsScannerIter
   }
 
 void
 CopyUnicodeTo( const nsScannerIterator& aSrcStart,
                const nsScannerIterator& aSrcEnd,
                nsAString& aDest )
   {
     nsAString::iterator writer;
-    if (!EnsureStringLength(aDest, Distance(aSrcStart, aSrcEnd))) {
+    if (!aDest.SetLength(Distance(aSrcStart, aSrcEnd), mozilla::fallible_t())) {
       aDest.Truncate();
       return; // out of memory
     }
     aDest.BeginWriting(writer);
     nsScannerIterator fromBegin(aSrcStart);
     
     copy_multifragment_string(fromBegin, aSrcEnd, writer);
   }
@@ -513,17 +513,17 @@ AppendUnicodeTo( const nsScannerIterator
 
 void
 AppendUnicodeTo( const nsScannerIterator& aSrcStart,
                  const nsScannerIterator& aSrcEnd,
                  nsAString& aDest )
   {
     nsAString::iterator writer;
     uint32_t oldLength = aDest.Length();
-    if (!EnsureStringLength(aDest, oldLength + Distance(aSrcStart, aSrcEnd)))
+    if (!aDest.SetLength(oldLength + Distance(aSrcStart, aSrcEnd), mozilla::fallible_t()))
       return; // out of memory
     aDest.BeginWriting(writer).advance(oldLength);
     nsScannerIterator fromBegin(aSrcStart);
     
     copy_multifragment_string(fromBegin, aSrcEnd, writer);
   }
 
 bool
--- a/widget/windows/nsIMM32Handler.cpp
+++ b/widget/windows/nsIMM32Handler.cpp
@@ -1663,17 +1663,17 @@ nsIMM32Handler::SetTextRangeList(nsTArra
 
 void
 nsIMM32Handler::GetCompositionString(const nsIMEContext &aIMEContext,
                                      DWORD aIndex)
 {
   // Retrieve the size of the required output buffer.
   long lRtn = ::ImmGetCompositionStringW(aIMEContext.get(), aIndex, NULL, 0);
   if (lRtn < 0 ||
-      !EnsureStringLength(mCompositionString, (lRtn / sizeof(WCHAR)) + 1)) {
+      !mCompositionString.SetLength((lRtn / sizeof(WCHAR)) + 1, mozilla::fallible_t())) {
     PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
       ("IMM32: GetCompositionString, FAILED by OOM\n"));
     return; // Error or out of memory.
   }
 
   // Actually retrieve the composition string information.
   lRtn = ::ImmGetCompositionStringW(aIMEContext.get(), aIndex,
                                     (LPVOID)mCompositionString.BeginWriting(),
@@ -1730,17 +1730,17 @@ bool
 nsIMM32Handler::ConvertToANSIString(const nsAFlatString& aStr, UINT aCodePage,
                                    nsACString& aANSIStr)
 {
   int len = ::WideCharToMultiByte(aCodePage, 0,
                                   (LPCWSTR)aStr.get(), aStr.Length(),
                                   NULL, 0, NULL, NULL);
   NS_ENSURE_TRUE(len >= 0, false);
 
-  if (!EnsureStringLength(aANSIStr, len)) {
+  if (!aANSIStr.SetLength(len, mozilla::fallible_t())) {
     PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
       ("IMM32: ConvertToANSIString, FAILED by OOM\n"));
     return false;
   }
   ::WideCharToMultiByte(aCodePage, 0, (LPCWSTR)aStr.get(), aStr.Length(),
                         (LPSTR)aANSIStr.BeginWriting(), len, NULL, NULL);
   return true;
 }
--- a/xpcom/io/nsBinaryStream.cpp
+++ b/xpcom/io/nsBinaryStream.cpp
@@ -655,17 +655,17 @@ nsBinaryInputStream::ReadString(nsAStrin
     if (NS_FAILED(rv)) return rv;
 
     if (length == 0) {
       aString.Truncate();
       return NS_OK;
     }
 
     // pre-allocate output buffer, and get direct access to buffer...
-    if (!EnsureStringLength(aString, length))
+    if (!aString.SetLength(length, mozilla::fallible_t()))
         return NS_ERROR_OUT_OF_MEMORY;
 
     nsAString::iterator start;
     aString.BeginWriting(start);
     
     WriteStringClosure closure;
     closure.mWriteCursor = start.get();
     closure.mHasCarryoverByte = false;
--- a/xpcom/io/nsLocalFileWin.cpp
+++ b/xpcom/io/nsLocalFileWin.cpp
@@ -3422,17 +3422,17 @@ nsDriveEnumerator::~nsDriveEnumerator()
 
 nsresult nsDriveEnumerator::Init()
 {
     /* If the length passed to GetLogicalDriveStrings is smaller
      * than the length of the string it would return, it returns
      * the length required for the string. */
     DWORD length = GetLogicalDriveStringsW(0, 0);
     /* The string is null terminated */
-    if (!EnsureStringLength(mDrives, length+1))
+    if (!mDrives.SetLength(length+1, fallible_t()))
         return NS_ERROR_OUT_OF_MEMORY;
     if (!GetLogicalDriveStringsW(length, mDrives.BeginWriting()))
         return NS_ERROR_FAILURE;
     mDrives.BeginReading(mStartOfCurrentDrive);
     mDrives.EndReading(mEndOfDrivesString);
     return NS_OK;
 }
 
--- a/xpcom/io/nsNativeCharsetUtils.cpp
+++ b/xpcom/io/nsNativeCharsetUtils.cpp
@@ -783,17 +783,17 @@ NS_CopyNativeToUnicode(const nsACString 
 
     //
     // OPTIMIZATION: preallocate space for largest possible result; convert
     // directly into the result buffer to avoid intermediate buffer copy.
     //
     // this will generally result in a larger allocation, but that seems
     // better than an extra buffer copy.
     //
-    if (!EnsureStringLength(output, inputLen))
+    if (!output.SetLength(inputLen, fallible_t()))
         return NS_ERROR_OUT_OF_MEMORY;
     nsAString::iterator out_iter;
     output.BeginWriting(out_iter);
 
     PRUnichar *result = out_iter.get();
     uint32_t resultLeft = inputLen;
 
     const char *buf = iter.get();
@@ -869,16 +869,18 @@ NS_ShutdownNativeCharsetUtils()
 // XP_WIN
 //-----------------------------------------------------------------------------
 #elif defined(XP_WIN)
 
 #include <windows.h>
 #include "nsAString.h"
 #include "nsReadableUtils.h"
 
+using namespace mozilla;
+
 nsresult
 NS_CopyNativeToUnicode(const nsACString &input, nsAString &output)
 {
     uint32_t inputLen = input.Length();
 
     nsACString::const_iterator iter;
     input.BeginReading(iter);
 
@@ -886,17 +888,17 @@ NS_CopyNativeToUnicode(const nsACString 
 
     // determine length of result
     uint32_t resultLen = 0;
     int n = ::MultiByteToWideChar(CP_ACP, 0, buf, inputLen, NULL, 0);
     if (n > 0)
         resultLen += n;
 
     // allocate sufficient space
-    if (!EnsureStringLength(output, resultLen))
+    if (!output.SetLength(resultLen, fallible_t()))
         return NS_ERROR_OUT_OF_MEMORY;
     if (resultLen > 0) {
         nsAString::iterator out_iter;
         output.BeginWriting(out_iter);
 
         PRUnichar *result = out_iter.get();
 
         ::MultiByteToWideChar(CP_ACP, 0, buf, inputLen, result, resultLen);
@@ -917,17 +919,17 @@ NS_CopyUnicodeToNative(const nsAString  
     // determine length of result
     uint32_t resultLen = 0;
 
     int n = ::WideCharToMultiByte(CP_ACP, 0, buf, inputLen, NULL, 0, NULL, NULL);
     if (n > 0)
         resultLen += n;
 
     // allocate sufficient space
-    if (!EnsureStringLength(output, resultLen))
+    if (!output.SetLength(resultLen, fallible_t()))
         return NS_ERROR_OUT_OF_MEMORY;
     if (resultLen > 0) {
         nsACString::iterator out_iter;
         output.BeginWriting(out_iter);
 
         // default "defaultChar" is '?', which is an illegal character on windows
         // file system.  That will cause file uncreatable. Change it to '_'
         const char defaultChar = '_';
@@ -984,30 +986,32 @@ NS_ConvertWtoA(const PRUnichar *aStrInW,
 #define INCL_DOS
 #include <os2.h>
 #include <uconv.h>
 #include "nsAString.h"
 #include "nsReadableUtils.h"
 #include <ulserrno.h>
 #include "nsNativeCharsetUtils.h"
 
+using namespace mozilla;
+
 static UconvObject UnicodeConverter = NULL;
 
 nsresult
 NS_CopyNativeToUnicode(const nsACString &input, nsAString  &output)
 {
     uint32_t inputLen = input.Length();
 
     nsACString::const_iterator iter;
     input.BeginReading(iter);
     const char *inputStr = iter.get();
 
     // determine length of result
     uint32_t resultLen = inputLen;
-    if (!EnsureStringLength(output, resultLen))
+    if (!output.SetLength(resultLen, fallible_t()))
         return NS_ERROR_OUT_OF_MEMORY;
 
     nsAString::iterator out_iter;
     output.BeginWriting(out_iter);
     UniChar *result = (UniChar*)out_iter.get();
 
     size_t cSubs = 0;
     size_t resultLeft = resultLen;
@@ -1038,17 +1042,17 @@ NS_CopyUnicodeToNative(const nsAString &
 
     nsAString::const_iterator iter;
     input.BeginReading(iter);
     UniChar* inputStr = (UniChar*) const_cast<PRUnichar*>(iter.get());
 
     // maximum length of unicode string of length x converted to native
     // codepage is x*2
     size_t resultLen = inputLen * 2;
-    if (!EnsureStringLength(output, resultLen))
+    if (!output.SetLength(resultLen, fallible_t()))
         return NS_ERROR_OUT_OF_MEMORY;
 
     nsACString::iterator out_iter;
     output.BeginWriting(out_iter);
     char *result = out_iter.get();
 
     size_t cSubs = 0;
     size_t resultLeft = resultLen;