Bug 1388253 - Convert nsTextFormatter:[v]smprintf() use to [v]ssprintf() in comm-central. r=jorgk.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 08 Aug 2017 18:52:48 +1000
changeset 29512 cc48357b48b1ecc798aa3de9060abcaf592aabfe
parent 29511 d6a93b3c001232129c25cada11571e0c5b0412ee
child 29513 15610850d580eabf5210c00a9e4000c8ac597cf8
push id378
push userclokep@gmail.com
push dateMon, 13 Nov 2017 18:45:35 +0000
reviewersjorgk
bugs1388253
Bug 1388253 - Convert nsTextFormatter:[v]smprintf() use to [v]ssprintf() in comm-central. r=jorgk.
mailnews/base/search/src/nsMsgFilterList.cpp
mailnews/compose/src/nsMsgSend.cpp
mailnews/compose/src/nsSmtpProtocol.cpp
mailnews/imap/src/nsImapMailFolder.cpp
mailnews/import/outlook/src/nsOutlookImport.cpp
mailnews/import/src/nsImportAddressBooks.cpp
mailnews/import/src/nsImportMail.cpp
mailnews/import/text/src/nsTextImport.cpp
mailnews/import/vcard/src/nsVCardImport.cpp
mailnews/import/winlivemail/nsWMImport.cpp
mailnews/local/src/nsPop3Protocol.cpp
mailnews/mime/emitters/nsMimeBaseEmitter.cpp
--- a/mailnews/base/search/src/nsMsgFilterList.cpp
+++ b/mailnews/base/search/src/nsMsgFilterList.cpp
@@ -572,20 +572,20 @@ nsresult nsMsgFilterList::LoadTextFilter
           if (NS_FAILED(err))
               break;
 
           filter->SetFilterName(unicodeStr);
         }
         else
         {
           // ### fix me - this is silly.
-          char16_t *unicodeString =
-            nsTextFormatter::smprintf(unicodeFormatter, value.get());
-          filter->SetFilterName(nsDependentString(unicodeString));
-          free(unicodeString);
+          nsString unicodeString;
+          nsTextFormatter::ssprintf(unicodeString, unicodeFormatter,
+                                    value.get());
+          filter->SetFilterName(unicodeString);
         }
         m_curFilter = filter;
         m_filters.AppendElement(filter);
       }
       break;
     case nsIMsgFilterList::attribEnabled:
       if (m_curFilter)
         m_curFilter->SetEnabled(StrToBool(value));
--- a/mailnews/compose/src/nsMsgSend.cpp
+++ b/mailnews/compose/src/nsMsgSend.cpp
@@ -4310,17 +4310,17 @@ nsMsgComposeAndSend::MimeDoFCC(nsIFile  
                                const char       *fcc_header,
                                const char       *news_url)
 {
   nsresult      status = NS_OK;
   char          *ibuffer = nullptr;
   uint32_t      n;
   bool          folderIsLocal = true;
   nsCString     tmpUri;
-  char16_t     *printfString = nullptr;
+  nsString      printfString;
   nsString msg;
   nsCOMPtr<nsIMsgFolder> folder;
 
   if (mSendProgress)
     mSendProgress->OnProgressChange(nullptr, nullptr, 0, 0, 0, -1);
 
   //
   // Ok, this is here to keep track of this for 2 copy operations...
@@ -4483,24 +4483,21 @@ nsMsgComposeAndSend::MimeDoFCC(nsIFile  
     {
       nsCOMPtr<nsIRDFResource> res;
       rdfService->GetResource(tmpUri, getter_AddRefs(res));
       nsCOMPtr<nsIMsgFolder> folder = do_QueryInterface(res);
       if (folder)
         folder->GetName(mSavedToFolderName);
     }
     if (!mSavedToFolderName.IsEmpty())
-      printfString = nsTextFormatter::smprintf(msg.get(), mSavedToFolderName.get());
+      nsTextFormatter::ssprintf(printfString, msg.get(),
+                                mSavedToFolderName.get());
     else
-      printfString = nsTextFormatter::smprintf(msg.get(), "?");
-    if (printfString)
-    {
-      SetStatusMessage(nsDependentString(printfString));
-      PR_Free(printfString);
-    }
+      nsTextFormatter::ssprintf(printfString, msg.get(), "?");
+    SetStatusMessage(printfString);
   }
 
   if (folderIsLocal)
   {
     char *envelopeLine = nsMsgGetEnvelopeLine();
     uint32_t   len = PL_strlen(envelopeLine);
 
     rv = tempOutfile->Write(envelopeLine, len, &n);
--- a/mailnews/compose/src/nsSmtpProtocol.cpp
+++ b/mailnews/compose/src/nsSmtpProtocol.cpp
@@ -76,17 +76,17 @@ nsresult nsExplainErrorDetails(nsISmtpUr
   NS_ENSURE_ARG(aSmtpUrl);
 
   va_list args;
 
   nsCOMPtr<nsIPrompt> dialog;
   aSmtpUrl->GetPrompt(getter_AddRefs(dialog));
   NS_ENSURE_TRUE(dialog, NS_ERROR_FAILURE);
 
-  char16_t *  msg;
+  nsString msg;
   nsString eMsg;
   nsCOMPtr<nsIStringBundleService> bundleService =
     mozilla::services::GetStringBundleService();
   NS_ENSURE_TRUE(bundleService, NS_ERROR_UNEXPECTED);
   nsCOMPtr<nsIStringBundle> bundle;
   nsresult rv = bundleService->CreateBundle(
     "chrome://messenger/locale/messengercompose/composeMsgs.properties",
     getter_AddRefs(bundle));
@@ -99,47 +99,43 @@ nsresult nsExplainErrorDetails(nsISmtpUr
 // Temporary workaroung until bug 783526 is fixed.
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wswitch"
 #endif
   switch (aCode)
   {
     case NS_ERROR_ILLEGAL_LOCALPART:
       bundle->GetStringFromName("errorIllegalLocalPart", eMsg);
-      msg = nsTextFormatter::vsmprintf(eMsg.get(), args);
+      nsTextFormatter::vssprintf(msg, eMsg.get(), args);
       break;
     case NS_ERROR_SMTP_SERVER_ERROR:
     case NS_ERROR_TCP_READ_ERROR:
     case NS_ERROR_SMTP_TEMP_SIZE_EXCEEDED:
     case NS_ERROR_SMTP_PERM_SIZE_EXCEEDED_1:
     case NS_ERROR_SMTP_PERM_SIZE_EXCEEDED_2:
     case NS_ERROR_SENDING_FROM_COMMAND:
     case NS_ERROR_SENDING_RCPT_COMMAND:
     case NS_ERROR_SENDING_DATA_COMMAND:
     case NS_ERROR_SENDING_MESSAGE:
     case NS_ERROR_SMTP_GREETING:
       exitString = errorStringNameForErrorCode(aCode);
       bundle->GetStringFromName(exitString, eMsg);
-      msg = nsTextFormatter::vsmprintf(eMsg.get(), args);
+      nsTextFormatter::vssprintf(msg, eMsg.get(), args);
       break;
     default:
       NS_WARNING("falling to default error code");
       bundle->GetStringFromName("communicationsError", eMsg);
-      msg = nsTextFormatter::smprintf(eMsg.get(), aCode);
+      nsTextFormatter::ssprintf(msg, eMsg.get(), aCode);
       break;
   }
 #ifdef __GNUC__
 #pragma GCC diagnostic pop
 #endif
 
-  if (msg)
-  {
-    rv = dialog->Alert(nullptr, msg);
-    free(msg);
-  }
+  rv = dialog->Alert(nullptr, msg.get());
 
   va_end (args);
 
   return rv;
 }
 
 /* RFC 1891 -- extended smtp value encoding scheme
 
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -6709,19 +6709,19 @@ nsImapMailFolder::ProgressStatusString(n
   if (aProtocol && !progressMsg.IsEmpty())
   {
     nsCOMPtr <nsIImapUrl> imapUrl;
     aProtocol->GetRunningImapURL(getter_AddRefs(imapUrl));
     if (imapUrl)
     {
       if (extraInfo)
       {
-        char16_t *printfString = nsTextFormatter::smprintf(progressMsg.get(), extraInfo);
-        if (printfString)
-          progressMsg.Adopt(printfString);
+        nsString printfString;
+        nsTextFormatter::ssprintf(printfString, progressMsg.get(), extraInfo);
+        progressMsg = printfString;
       }
 
       DisplayStatusMsg(imapUrl, progressMsg);
     }
   }
   return NS_OK;
 }
 
--- a/mailnews/import/outlook/src/nsOutlookImport.cpp
+++ b/mailnews/import/outlook/src/nsOutlookImport.cpp
@@ -344,32 +344,32 @@ void ImportOutlookMailImpl::AddLinebreak
 }
 
 void ImportOutlookMailImpl::ReportSuccess(nsString& name, int32_t count, nsString *pStream)
 {
   if (!pStream)
     return;
   // load the success string
   char16_t *pFmt = nsOutlookStringBundle::GetStringByID(OUTLOOKIMPORT_MAILBOX_SUCCESS);
-  char16_t *pText = nsTextFormatter::smprintf(pFmt, name.get(), count);
+  nsString pText;
+  nsTextFormatter::ssprintf(pText, pFmt, name.get(), count);
   pStream->Append(pText);
-  free(pText);
   nsOutlookStringBundle::FreeString(pFmt);
   AddLinebreak(pStream);
 }
 
 void ImportOutlookMailImpl::ReportError(int32_t errorNum, nsString& name, nsString *pStream)
 {
   if (!pStream)
     return;
   // load the error string
   char16_t *pFmt = nsOutlookStringBundle::GetStringByID(errorNum);
-  char16_t *pText = nsTextFormatter::smprintf(pFmt, name.get());
+  nsString pText;
+  nsTextFormatter::ssprintf(pText, pFmt, name.get());
   pStream->Append(pText);
-  free(pText);
   nsOutlookStringBundle::FreeString(pFmt);
   AddLinebreak(pStream);
 }
 
 
 void ImportOutlookMailImpl::SetLogs(nsString& success, nsString& error, char16_t **pError, char16_t **pSuccess)
 {
   if (pError)
@@ -571,14 +571,14 @@ NS_IMETHODIMP ImportOutlookAddressImpl::
 }
 
 void ImportOutlookAddressImpl::ReportSuccess(nsString& name, nsString *pStream)
 {
   if (!pStream)
     return;
   // load the success string
   char16_t *pFmt = nsOutlookStringBundle::GetStringByID(OUTLOOKIMPORT_ADDRESS_SUCCESS);
-  char16_t *pText = nsTextFormatter::smprintf(pFmt, name.get());
+  nsString pText;
+  nsTextFormatter::ssprintf(pText, pFmt, name.get());
   pStream->Append(pText);
-  free(pText);
   nsOutlookStringBundle::FreeString(pFmt);
   ImportOutlookMailImpl::AddLinebreak(pStream);
 }
--- a/mailnews/import/src/nsImportAddressBooks.cpp
+++ b/mailnews/import/src/nsImportAddressBooks.cpp
@@ -782,19 +782,19 @@ AddressThreadData::~AddressThreadData()
 void nsImportGenericAddressBooks::ReportError(const char16_t *pName,
                                               nsString *pStream,
                                               nsIStringBundle* aBundle)
 {
   if (!pStream)
     return;
   // load the error string
   char16_t *pFmt = nsImportStringBundle::GetStringByID(IMPORT_ERROR_GETABOOK, aBundle);
-  char16_t *pText = nsTextFormatter::smprintf(pFmt, pName);
+  nsString pText;
+  nsTextFormatter::ssprintf(pText, pFmt, pName);
   pStream->Append(pText);
-  free(pText);
   NS_Free(pFmt);
   pStream->AppendLiteral(MSG_LINEBREAK);
 }
 
 static void ImportAddressThread(void *stuff)
 {
   IMPORT_LOG0("In Begin ImportAddressThread\n");
 
--- a/mailnews/import/src/nsImportMail.cpp
+++ b/mailnews/import/src/nsImportMail.cpp
@@ -595,19 +595,19 @@ NS_IMETHODIMP nsImportGenericMail::GetPr
 
 void nsImportGenericMail::ReportError(int32_t id, const char16_t *pName, nsString *pStream, nsIStringBundle *aBundle)
 {
   if (!pStream)
     return;
 
   // load the error string
   char16_t *pFmt = nsImportStringBundle::GetStringByID(id, aBundle);
-  char16_t *pText = nsTextFormatter::smprintf(pFmt, pName);
+  nsString pText;
+  nsTextFormatter::ssprintf(pText, pFmt, pName);
   pStream->Append(pText);
-  free(pText);
   NS_Free(pFmt);
   pStream->Append(NS_ConvertASCIItoUTF16(MSG_LINEBREAK));
 }
 
 
 void nsImportGenericMail::SetLogs(nsString& success, nsString& error, nsISupportsString *pSuccess, nsISupportsString *pError)
 {
     nsAutoString str;
--- a/mailnews/import/text/src/nsTextImport.cpp
+++ b/mailnews/import/text/src/nsTextImport.cpp
@@ -332,34 +332,34 @@ void ImportAddressImpl::ReportSuccess(ns
 {
   if (!pStream)
     return;
 
   // load the success string
   char16_t *pFmt =
     nsImportStringBundle::GetStringByID(TEXTIMPORT_ADDRESS_SUCCESS, pBundle);
 
-  char16_t *pText = nsTextFormatter::smprintf(pFmt, name.get());
+  nsString pText;
+  nsTextFormatter::ssprintf(pText, pFmt, name.get());
   pStream->Append(pText);
-  free(pText);
   NS_Free(pFmt);
   pStream->Append(char16_t('\n'));
 }
 
 void ImportAddressImpl::ReportError(int32_t errorNum, nsString& name,
                                     nsString *pStream, nsIStringBundle* pBundle)
 {
   if (!pStream)
     return;
 
   // load the error string
   char16_t *pFmt = nsImportStringBundle::GetStringByID(errorNum, pBundle);
-  char16_t *pText = nsTextFormatter::smprintf(pFmt, name.get());
+  nsString pText;
+  nsTextFormatter::ssprintf(pText, pFmt, name.get());
   pStream->Append(pText);
-  free(pText);
   NS_Free(pFmt);
   pStream->Append(char16_t('\n'));
 }
 
 void ImportAddressImpl::SetLogs(nsString& success, nsString& error, char16_t **pError, char16_t **pSuccess)
 {
   if (pError)
     *pError = ToNewUnicode(error);
--- a/mailnews/import/vcard/src/nsVCardImport.cpp
+++ b/mailnews/import/vcard/src/nsVCardImport.cpp
@@ -289,35 +289,35 @@ void ImportVCardAddressImpl::ReportSucce
 {
   if (!pStream)
     return;
 
   // load the success string
   char16_t *pFmt = nsImportStringBundle::GetStringByName(
       "vCardImportAddressSuccess", pBundle);
 
-  char16_t *pText = nsTextFormatter::smprintf(pFmt, name.get());
+  nsString pText;
+  nsTextFormatter::ssprintf(pText, pFmt, name.get());
   pStream->Append(pText);
-  free(pText);
   NS_Free(pFmt);
   pStream->Append(char16_t('\n'));
 }
 
 void ImportVCardAddressImpl::ReportError(
     const char *errorName, nsString& name, nsString *pStream,
     nsIStringBundle* pBundle)
 {
   if (!pStream)
     return;
 
   // load the error string
   char16_t *pFmt = nsImportStringBundle::GetStringByName(errorName, pBundle);
-  char16_t *pText = nsTextFormatter::smprintf(pFmt, name.get());
+  nsString pText;
+  nsTextFormatter::ssprintf(pText, pFmt, name.get());
   pStream->Append(pText);
-  free(pText);
   NS_Free(pFmt);
   pStream->Append(char16_t('\n'));
 }
 
 void ImportVCardAddressImpl::SetLogs(
     nsString& success, nsString& error,
     char16_t **pError, char16_t **pSuccess)
 { 
--- a/mailnews/import/winlivemail/nsWMImport.cpp
+++ b/mailnews/import/winlivemail/nsWMImport.cpp
@@ -195,32 +195,32 @@ void ImportWMMailImpl::AddLinebreak(nsSt
 }
 
 void ImportWMMailImpl::ReportSuccess(nsString& name, int32_t count, nsString *pStream)
 {
   if (!pStream)
     return;
   // load the success string
   char16_t *pFmt = nsWMStringBundle::GetStringByID(WMIMPORT_MAILBOX_SUCCESS);
-  char16_t *pText = nsTextFormatter::smprintf(pFmt, name.get(), count);
+  nsString pText;
+  nsTextFormatter::ssprintf(pText, pFmt, name.get(), count);
   pStream->Append(pText);
-  free(pText);
   nsWMStringBundle::FreeString(pFmt);
   AddLinebreak(pStream);
 }
 
 void ImportWMMailImpl::ReportError(int32_t errorNum, nsString& name, nsString *pStream)
 {
   if (!pStream)
     return;
   // load the error string
   char16_t *pFmt = nsWMStringBundle::GetStringByID(errorNum);
-  char16_t *pText = nsTextFormatter::smprintf(pFmt, name.get());
+  nsString pText;
+  nsTextFormatter::ssprintf(pText, pFmt, name.get());
   pStream->Append(pText);
-  free(pText);
   nsWMStringBundle::FreeString(pFmt);
   AddLinebreak(pStream);
 }
 
 void ImportWMMailImpl::SetLogs(nsString& success, nsString& error,
                                char16_t **pError, char16_t **pSuccess)
 {
   if (pError)
--- a/mailnews/local/src/nsPop3Protocol.cpp
+++ b/mailnews/local/src/nsPop3Protocol.cpp
@@ -3507,22 +3507,22 @@ nsPop3Protocol::TopResponse(nsIInputStre
 
     nsString statusTemplate;
     mLocalBundle->GetStringFromName(
       "pop3ServerDoesNotSupportTopCommand",
       statusTemplate);
     if (!statusTemplate.IsEmpty())
     {
       nsAutoCString hostName;
-      char16_t * statusString = nullptr;
+      nsString statusString;
       m_url->GetHost(hostName);
 
-      statusString = nsTextFormatter::smprintf(statusTemplate.get(), hostName.get());
-      UpdateStatusWithString(statusString);
-      free(statusString);
+      nsTextFormatter::ssprintf(statusString, statusTemplate.get(),
+                                hostName.get());
+      UpdateStatusWithString(statusString.get());
     }
 
     if (m_prefAuthMethods != POP3_HAS_AUTH_USER &&
         TestCapFlag(POP3_HAS_XSENDER))
       m_pop3ConData->next_state = POP3_SEND_XSENDER;
     else
       m_pop3ConData->next_state = POP3_SEND_RETR;
     return(0);
--- a/mailnews/mime/emitters/nsMimeBaseEmitter.cpp
+++ b/mailnews/mime/emitters/nsMimeBaseEmitter.cpp
@@ -727,22 +727,21 @@ nsMimeBaseEmitter::GenerateDateString(co
   if (NS_SUCCEEDED(rv))
   {
     if (displaySenderTimezone)
     {
       // offset of local time from UTC in minutes
       int32_t senderoffset = (explodedMsgTime.tm_params.tp_gmt_offset +
                               explodedMsgTime.tm_params.tp_dst_offset) / 60;
       // append offset to date string
-      char16_t *tzstring =
-        nsTextFormatter::smprintf(u" %+05d",
-                                  (senderoffset / 60 * 100) +
-                                  (senderoffset % 60));
+      nsString tzstring;
+      nsTextFormatter::ssprintf(tzstring, u" %+05d",
+                                (senderoffset / 60 * 100) +
+                                (senderoffset % 60));
       formattedDateString.Append(tzstring);
-      free(tzstring);
     }
 
     CopyUTF16toUTF8(formattedDateString, formattedDate);
   }
 
   return rv;
 }