Bug 1527277 - Part 2: Use unique pointer to manage buffer lifetime. r=peterv
authorEric Rahm <erahm@mozilla.com>
Thu, 21 Feb 2019 23:06:04 +0000
changeset 462689 7ce2309548dab8af0285f3224cb344640089f59b
parent 462688 62aba7d6d779e6a5e3a088b94ea0df7eef2d92bd
child 462690 b4fef176bc8fde4e580823740639f51c6e43c58f
push id79792
push usererahm@mozilla.com
push dateWed, 06 Mar 2019 19:53:03 +0000
treeherderautoland@60142f1fcb4c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs1527277
milestone67.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 1527277 - Part 2: Use unique pointer to manage buffer lifetime. r=peterv Switch to managing the buffer lifetime with a UniquePtr. This will make handling errors simpler in the next patch. Differential Revision: https://phabricator.services.mozilla.com/D20579
dom/xslt/xslt/txFormatNumberFunctionCall.cpp
--- a/dom/xslt/xslt/txFormatNumberFunctionCall.cpp
+++ b/dom/xslt/xslt/txFormatNumberFunctionCall.cpp
@@ -249,22 +249,22 @@ nsresult txFormatNumberFunctionCall::eva
   nsAutoString res(prefix);
 
   int bufsize;
   if (value > 1)
     bufsize = (int)log10(value) + 30;
   else
     bufsize = 1 + 30;
 
-  char* buf = new char[bufsize];
+  auto buf = MakeUnique<char[]>(bufsize);
   int bufIntDigits, sign;
   char* endp;
-  PR_dtoa(value, 0, 0, &bufIntDigits, &sign, &endp, buf, bufsize - 1);
+  PR_dtoa(value, 0, 0, &bufIntDigits, &sign, &endp, buf.get(), bufsize - 1);
 
-  int buflen = endp - buf;
+  int buflen = endp - buf.get();
   int intDigits;
   intDigits = bufIntDigits > minIntegerSize ? bufIntDigits : minIntegerSize;
 
   if (groupSize < 0) groupSize = intDigits + 10;  // to simplify grouping
 
   // XXX We shouldn't use SetLength.
   res.SetLength(res.Length() + intDigits +     // integer digits
                 1 +                            // decimal separator
@@ -335,18 +335,16 @@ nsresult txFormatNumberFunctionCall::eva
   }
 
   if (!hasFraction && !intDigits && !carry) {
     // If we havn't added any characters we add a '0'
     // This can only happen for formats like '##.##'
     res.Append(format->mZeroDigit);
   }
 
-  delete[] buf;
-
   // Build suffix
   res.Append(suffix);
 
   return aContext->recycler()->getStringResult(res, aResult);
 }  //-- evaluate
 
 Expr::ResultType txFormatNumberFunctionCall::getReturnType() {
   return STRING_RESULT;