Bug 1388789 - change return values of nsTextFormatter::vs{s,v}printf; r=froydnj
authorTom Tromey <tom@tromey.com>
Tue, 05 Sep 2017 13:17:49 -0600
changeset 431520 2c6474a8bc311bd18f71d9a19d568a3a69210bd3
parent 431519 2aa6bbd7fca8687c08e107863baef93918f91788
child 431521 5a294c3eff7cad30386079148ed7ba6872283584
push id7784
push userryanvm@gmail.com
push dateThu, 21 Sep 2017 00:40:13 +0000
treeherdermozilla-beta@efff4f307675 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1388789
milestone57.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 1388789 - change return values of nsTextFormatter::vs{s,v}printf; r=froydnj nsTextFormatter::vsnprintf is defined to return uint32_t(-1) on error. However, it was not doing this. nsTextFormatter::vssprintf is defined as infallible; enforce this by having it return void. MozReview-Commit-ID: LdOhIHzRvAT
xpcom/string/nsTextFormatter.cpp
xpcom/string/nsTextFormatter.h
--- a/xpcom/string/nsTextFormatter.cpp
+++ b/xpcom/string/nsTextFormatter.cpp
@@ -1198,41 +1198,38 @@ StringStuff(SprintfStateStr* aState, con
   str->Append(aStr, aLen);
 
   aState->base = str->BeginWriting();
   aState->cur = aState->base + off;
 
   return 0;
 }
 
-uint32_t
+void
 nsTextFormatter::ssprintf(nsAString& aOut, const char16_t* aFmt, ...)
 {
   va_list ap;
-  uint32_t rv;
 
   va_start(ap, aFmt);
-  rv = nsTextFormatter::vssprintf(aOut, aFmt, ap);
+  nsTextFormatter::vssprintf(aOut, aFmt, ap);
   va_end(ap);
-  return rv;
 }
 
-uint32_t
+void
 nsTextFormatter::vssprintf(nsAString& aOut, const char16_t* aFmt, va_list aAp)
 {
   SprintfStateStr ss;
   ss.stuff = StringStuff;
   ss.base = 0;
   ss.cur = 0;
   ss.maxlen = 0;
   ss.stuffclosure = &aOut;
 
   aOut.Truncate();
-  int n = dosprintf(&ss, aFmt, aAp);
-  return n ? n - 1 : n;
+  dosprintf(&ss, aFmt, aAp);
 }
 
 /*
 ** Stuff routine that discards overflow data
 */
 static int
 LimitStuff(SprintfStateStr* aState, const char16_t* aStr, uint32_t aLen)
 {
@@ -1281,19 +1278,23 @@ nsTextFormatter::vsnprintf(char16_t* aOu
   if ((int32_t)aOutLen <= 0) {
     return 0;
   }
 
   ss.stuff = LimitStuff;
   ss.base = aOut;
   ss.cur = aOut;
   ss.maxlen = aOutLen;
-  (void) dosprintf(&ss, aFmt, aAp);
+  int result = dosprintf(&ss, aFmt, aAp);
 
   /* If we added chars, and we didn't append a null, do it now. */
   if ((ss.cur != ss.base) && (*(ss.cur - 1) != '\0')) {
     *(--ss.cur) = '\0';
   }
 
+  if (result < 0) {
+    return -1;
+  }
+
   n = ss.cur - ss.base;
   return n ? n - 1 : n;
 }
 
--- a/xpcom/string/nsTextFormatter.h
+++ b/xpcom/string/nsTextFormatter.h
@@ -50,21 +50,21 @@ public:
    */
   static uint32_t snprintf(char16_t* aOut, uint32_t aOutLen,
                            const char16_t* aFmt, ...);
 
   /*
    * sprintf into an existing nsAString, overwriting any contents it already
    * has. Infallible.
    */
-  static uint32_t ssprintf(nsAString& aOut, const char16_t* aFmt, ...);
+  static void ssprintf(nsAString& aOut, const char16_t* aFmt, ...);
 
 private:
 
   /*
    * va_list forms of the above.
    */
   static uint32_t vsnprintf(char16_t* aOut, uint32_t aOutLen, const char16_t* aFmt,
                             va_list aAp);
-  static uint32_t vssprintf(nsAString& aOut, const char16_t* aFmt, va_list aAp);
+  static void vssprintf(nsAString& aOut, const char16_t* aFmt, va_list aAp);
 };
 
 #endif /* nsTextFormatter_h___ */