Bug 1388789 - make va_list nsTextFormatter private; r?froydnj draft
authorTom Tromey <tom@tromey.com>
Thu, 31 Aug 2017 15:21:37 -0600
changeset 667042 8fd592782c4970be571dc2e2d8925ae4e427b2bf
parent 666444 81341c1fc5aee29ef648126e9462bace07b526e7
child 667043 a4718aa876bfe428a5d7eec71279ceba10b3aac5
push id80599
push userbmo:ttromey@mozilla.com
push dateTue, 19 Sep 2017 16:49:35 +0000
reviewersfroydnj
bugs1388789
milestone57.0a1
Bug 1388789 - make va_list nsTextFormatter private; r?froydnj The runtime type-checking rewrite of nsTextFormatter will not support va_list uses. So, make these functions private and fix the sole user. MozReview-Commit-ID: IBWALVzIcHC
toolkit/components/commandlines/nsCommandLine.cpp
xpcom/string/nsTextFormatter.h
--- a/toolkit/components/commandlines/nsCommandLine.cpp
+++ b/toolkit/components/commandlines/nsCommandLine.cpp
@@ -478,24 +478,22 @@ nsCommandLine::Init(int32_t argc, const 
     appendArg(curarg);
   }
 
   mState = aState;
 
   return NS_OK;
 }
 
+template<typename ...T>
 static void
-LogConsoleMessage(const char16_t* fmt, ...)
+LogConsoleMessage(const char16_t* fmt, T... args)
 {
-  va_list args;
-  va_start(args, fmt);
   nsString msg;
-  nsTextFormatter::vssprintf(msg, fmt, args);
-  va_end(args);
+  nsTextFormatter::ssprintf(msg, fmt, args...);
 
   nsCOMPtr<nsIConsoleService> cs = do_GetService("@mozilla.org/consoleservice;1");
   if (cs)
     cs->LogStringMessage(msg.get());
 }
 
 nsresult
 nsCommandLine::EnumerateHandlers(EnumerateHandlersCallback aCallback, void *aClosure)
--- a/xpcom/string/nsTextFormatter.h
+++ b/xpcom/string/nsTextFormatter.h
@@ -53,16 +53,18 @@ public:
                            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, ...);
 
+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);
 };