Bug 1388789 - normalize null string handling in nsTextFormatter; r?froydnj draft
authorTom Tromey <tom@tromey.com>
Wed, 06 Sep 2017 08:38:44 -0600
changeset 667179 9a55eab03a95481d95781f9c63bcd0726f23609b
parent 667178 9b66b5eb81d52d479245c06a3d1ffa9c4892b607
child 667180 a88d7e6bab0c21399d978c6819ee4207ea7a9963
push id80636
push userbmo:ttromey@mozilla.com
push dateTue, 19 Sep 2017 20:02:29 +0000
reviewersfroydnj
bugs1388789
milestone57.0a1
Bug 1388789 - normalize null string handling in nsTextFormatter; r?froydnj The char* and char16_t* cases handled null strings differently; normalize them to both emit "(null)". MozReview-Commit-ID: IzRkc3pSSjl
xpcom/string/nsTextFormatter.cpp
--- a/xpcom/string/nsTextFormatter.cpp
+++ b/xpcom/string/nsTextFormatter.cpp
@@ -449,16 +449,20 @@ nsTextFormatter::cvt_S(SprintfStateStr* 
 ** Convert a string into its printable form.  |aWidth| is the output
 ** width. |aPrec| is the maximum number of characters of |aStr| to output,
 ** where -1 means until NUL.
 */
 int
 nsTextFormatter::cvt_s(nsTextFormatter::SprintfStateStr* aState, const char* aStr, int aWidth,
                        int aPrec, int aFlags)
 {
+  // Be sure to handle null the same way as %S.
+  if (aStr == nullptr) {
+    return cvt_S(aState, nullptr, aWidth, aPrec, aFlags);
+  }
   NS_ConvertUTF8toUTF16 utf16Val(aStr);
   return cvt_S(aState, utf16Val.get(), aWidth, aPrec, aFlags);
 }
 
 /*
 ** The workhorse sprintf code.
 */
 int