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
--- 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