Bug 998191, part 1: Use nsCString instead of char* in nsMsgCompFields, r=Neil
authorJoshua Cranmer <Pidgeot18@gmail.com>
Wed, 07 Jan 2015 15:57:26 -0600
changeset 21596 feaf7e10ead5c4ae21c126dd660212f5cb838a01
parent 21595 34becc11470eb00bccd7d41aedb1c62dd8d1558d
child 21597 67519bbca9702cfaa7f699b56c1f350673eebb14
push id1305
push usermbanner@mozilla.com
push dateMon, 23 Feb 2015 19:48:12 +0000
treeherdercomm-beta@3ae4f13858fd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeil
bugs998191
Bug 998191, part 1: Use nsCString instead of char* in nsMsgCompFields, r=Neil
mailnews/compose/src/nsMsgCompFields.cpp
mailnews/compose/src/nsMsgCompFields.h
--- a/mailnews/compose/src/nsMsgCompFields.cpp
+++ b/mailnews/compose/src/nsMsgCompFields.cpp
@@ -18,20 +18,16 @@
 
 using namespace mozilla::mailnews;
 
 /* the following macro actually implement addref, release and query interface for our component. */
 NS_IMPL_ISUPPORTS(nsMsgCompFields, nsIMsgCompFields)
 
 nsMsgCompFields::nsMsgCompFields()
 {
-  int16_t i;
-  for (i = 0; i < MSG_MAX_HEADERS; i ++)
-    m_headers[i] = nullptr;
-
   m_body.Truncate();
 
   m_attachVCard = false;
   m_forcePlainText = false;
   m_useMultipartAlternative = false;
   m_returnReceipt = false;
   m_receiptHeaderType = nsIMsgMdnGenerator::eDntType;
   m_DSN = false;
@@ -46,55 +42,33 @@ nsMsgCompFields::nsMsgCompFields()
                                               NS_LITERAL_STRING("UTF-8"), charset);
 
   LossyCopyUTF16toASCII(charset, m_DefaultCharacterSet); // Charsets better be ASCII
   SetCharacterSet(m_DefaultCharacterSet.get());
 }
 
 nsMsgCompFields::~nsMsgCompFields()
 {
-  int16_t i;
-  for (i = 0; i < MSG_MAX_HEADERS; i ++)
-    PR_FREEIF(m_headers[i]);
 }
 
 nsresult nsMsgCompFields::SetAsciiHeader(MsgHeaderID header, const char *value)
 {
   NS_ASSERTION(header >= 0 && header < MSG_MAX_HEADERS,
                "Invalid message header index!");
 
-  nsresult rv = NS_OK;
-  char* old = m_headers[header]; /* Done with careful paranoia, in case the
-                                    value given is the old value (or worse,
-                                    a substring of the old value, as does
-                                    happen here and there.)
-                                  */
-  if (value != old)
-  {
-    if (value)
-    {
-        m_headers[header] = strdup(value);
-        if (!m_headers[header])
-           rv = NS_ERROR_OUT_OF_MEMORY;
-    }
-    else
-      m_headers[header] = nullptr;
-
-    PR_FREEIF(old);
-  }
-
-  return rv;
+  m_headers[header] = value;
+  return NS_OK;
 }
 
 const char* nsMsgCompFields::GetAsciiHeader(MsgHeaderID header)
 {
   NS_ASSERTION(header >= 0 && header < MSG_MAX_HEADERS,
                "Invalid message header index!");
 
-  return m_headers[header] ? m_headers[header] : "";
+  return m_headers[header].get();
 }
 
 nsresult nsMsgCompFields::SetUnicodeHeader(MsgHeaderID header, const nsAString& value)
 {
   return SetAsciiHeader(header, NS_ConvertUTF16toUTF8(value).get());
 }
 
 nsresult nsMsgCompFields::GetUnicodeHeader(MsgHeaderID header, nsAString& aResult)
--- a/mailnews/compose/src/nsMsgCompFields.h
+++ b/mailnews/compose/src/nsMsgCompFields.h
@@ -135,17 +135,17 @@ public:
   nsresult SetBody(const char *value);
   const char* GetBody();
 
   nsresult SplitRecipientsEx(const nsAString &recipients,
                              nsTArray<nsMsgRecipient> &aResult);
 
 protected:
   virtual ~nsMsgCompFields();
-  char*       m_headers[MSG_MAX_HEADERS];
+  nsCString m_headers[MSG_MAX_HEADERS];
   nsCString   m_body;
   nsCOMArray<nsIMsgAttachment> m_attachments;
   bool        m_attachVCard;
   bool        m_attachmentReminder;
   bool        m_forcePlainText;
   bool        m_useMultipartAlternative;
   bool        m_returnReceipt;
   bool        m_DSN;