Bug 1388789 - normalize null string handling in nsTextFormatter; r=froydnj
authorTom Tromey <tom@tromey.com>
Wed, 06 Sep 2017 08:38:44 -0600
changeset 431523 2409839d34ba36791e3910083afb6d364a85d0bc
parent 431522 e261f147b65f0871223d21bcb170b05da79c4d8c
child 431524 76ba215c8f256d9f518c1107c89ec037fedc29b7
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 - 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