Bug 186724 - add checks to see if SetSpec() failed in various spots. r=bienvenu a=Standard8 for checkin to CLOSED TREE
authoraceman <acelists@atlas.sk>
Wed, 07 Mar 2012 16:00:33 +0000
changeset 11020 53fcee1f9ec3259491f61478e55e77620a0b67c6
parent 11019 4f7dd383534c3ff33a1ed57af246e56e39dc7349
child 11021 c1fa6cb7574e3303fc1579a3fb71bb124538c9a6
push id463
push userbugzilla@standard8.plus.com
push dateTue, 24 Apr 2012 17:34:51 +0000
treeherdercomm-beta@e53588e8f7b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbienvenu, Standard8
bugs186724
Bug 186724 - add checks to see if SetSpec() failed in various spots. r=bienvenu a=Standard8 for checkin to CLOSED TREE
mailnews/addrbook/src/nsAddbookUrl.cpp
mailnews/base/util/nsMsgUtils.cpp
mailnews/compose/src/nsMsgAttachmentHandler.cpp
mailnews/compose/src/nsSmtpService.cpp
mailnews/compose/src/nsSmtpUrl.cpp
mailnews/imap/src/nsImapService.cpp
mailnews/local/src/nsMailboxService.cpp
mailnews/news/src/nsNntpService.cpp
--- a/mailnews/addrbook/src/nsAddbookUrl.cpp
+++ b/mailnews/addrbook/src/nsAddbookUrl.cpp
@@ -57,17 +57,18 @@ nsAddbookUrl::~nsAddbookUrl()
 {
 }
 
 NS_IMPL_ISUPPORTS2(nsAddbookUrl, nsIAddbookUrl, nsIURI)
 
 NS_IMETHODIMP 
 nsAddbookUrl::SetSpec(const nsACString &aSpec)
 {
-  m_baseURL->SetSpec(aSpec);
+  nsresult rv = m_baseURL->SetSpec(aSpec);
+  NS_ENSURE_SUCCESS(rv, rv);
   return ParseUrl();
 }
 
 nsresult nsAddbookUrl::ParseUrl()
 {
   nsCAutoString pathStr;
 
   nsresult rv = m_baseURL->GetPath(pathStr);
--- a/mailnews/base/util/nsMsgUtils.cpp
+++ b/mailnews/base/util/nsMsgUtils.cpp
@@ -191,17 +191,17 @@ nsresult CreateStartupUrl(const char *ur
   else if (PL_strncasecmp(uri, "news", 4) == 0)
   {
     nsCOMPtr<nsINntpUrl> nntpUrl = do_CreateInstance(kCNntpUrlCID, &rv);
     if (NS_SUCCEEDED(rv) && nntpUrl)
       rv = nntpUrl->QueryInterface(NS_GET_IID(nsIURI),
       (void**) aUrl);
   }
   if (*aUrl)
-    (*aUrl)->SetSpec(nsDependentCString(uri));
+    rv = (*aUrl)->SetSpec(nsDependentCString(uri));
   return rv;
 }
 
 
 // Where should this live? It's a utility used to convert a string priority,
 //  e.g., "High, Low, Normal" to an enum.
 // Perhaps we should have an interface that groups together all these
 //  utilities...
--- a/mailnews/compose/src/nsMsgAttachmentHandler.cpp
+++ b/mailnews/compose/src/nsMsgAttachmentHandler.cpp
@@ -576,18 +576,21 @@ nsMsgAttachmentHandler::SnarfMsgAttachme
       }
 
       nsCOMPtr<nsIStreamListener> convertedListener = do_QueryInterface(m_mime_parser, &rv);
       if (NS_FAILED(rv))
         goto done;
 
       nsCOMPtr<nsIURI> aURL;
       rv = messageService->GetUrlForUri(uri.get(), getter_AddRefs(aURL), nsnull);
-      if (aURL)
-        aURL->SetSpec(nsDependentCString(uri.get()));
+      if (aURL) {
+        rv = aURL->SetSpec(nsDependentCString(uri.get()));
+        if (NS_FAILED(rv))
+          goto done;
+      }
 
       rv = NS_NewInputStreamChannel(getter_AddRefs(m_converter_channel), aURL, nsnull);
       if (NS_FAILED(rv))
         goto done;
 
       rv = m_mime_parser->AsyncConvertData(
 		    "message/rfc822",
 		    "message/rfc822",
--- a/mailnews/compose/src/nsSmtpService.cpp
+++ b/mailnews/compose/src/nsSmtpService.cpp
@@ -200,17 +200,19 @@ nsresult NS_MsgBuildSmtpUrl(nsIFile * aF
   {
     urlSpec.Append(':');
     urlSpec.AppendInt(smtpPort);
   }
 
   nsCOMPtr<nsIMsgMailNewsUrl> url(do_QueryInterface(smtpUrl, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  url->SetSpec(urlSpec);
+  rv = url->SetSpec(urlSpec);
+  NS_ENSURE_SUCCESS(rv, rv);
+
   smtpUrl->SetRecipients(aRecipients);
   smtpUrl->SetRequestDSN(aRequestDSN);
   smtpUrl->SetPostMessageFile(aFilePath);
   smtpUrl->SetSenderIdentity(aSenderIdentity);
   smtpUrl->SetNotificationCallbacks(aNotificationCallbacks);
   smtpUrl->SetSmtpServer(aSmtpServer);
 
   nsCOMPtr<nsIPrompt> smtpPrompt(do_GetInterface(aNotificationCallbacks));
@@ -333,19 +335,20 @@ NS_IMETHODIMP nsSmtpService::NewURI(cons
       utf8Converter(do_GetService(NS_UTF8CONVERTERSERVICE_CONTRACTID, &rv));
     if (NS_SUCCEEDED(rv))
       rv = utf8Converter->ConvertURISpecToUTF8(aSpec, aOriginCharset, utf8Spec);
   }
 
   // utf8Spec is filled up only when aOriginCharset is specified and
   // the conversion is successful. Otherwise, fall back to aSpec.
   if (aOriginCharset && NS_SUCCEEDED(rv))
-    mailtoUrl->SetSpec(utf8Spec);
+    rv = mailtoUrl->SetSpec(utf8Spec);
   else
-    mailtoUrl->SetSpec(aSpec);
+    rv = mailtoUrl->SetSpec(aSpec);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   mailtoUrl.forget(_retval);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsSmtpService::NewChannel(nsIURI *aURI, nsIChannel **_retval)
 {
   NS_ENSURE_ARG_POINTER(aURI);
--- a/mailnews/compose/src/nsSmtpUrl.cpp
+++ b/mailnews/compose/src/nsSmtpUrl.cpp
@@ -404,17 +404,18 @@ nsresult nsMailtoUrl::ParseMailtoUrl(cha
       }
     }
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMailtoUrl::SetSpec(const nsACString &aSpec)
 {
-  m_baseURL->SetSpec(aSpec);
+  nsresult rv = m_baseURL->SetSpec(aSpec);
+  NS_ENSURE_SUCCESS(rv, rv);
   return ParseUrl();
 }
 
 nsresult nsMailtoUrl::CleanupMailtoState()
 {
     m_ccPart = "";
     m_subjectPart = "";
     m_newsgroupPart = "";
--- a/mailnews/imap/src/nsImapService.cpp
+++ b/mailnews/imap/src/nsImapService.cpp
@@ -387,17 +387,18 @@ NS_IMETHODIMP nsImapService::OpenAttachm
       urlSpec.Append(msgKey);
       urlSpec.Append(uriMimePart);
 
       if (!uriMimePart.IsEmpty())
       {
         nsCOMPtr<nsIMsgMailNewsUrl> mailUrl (do_QueryInterface(imapUrl));
         if (mailUrl)
         {
-          mailUrl->SetSpec(urlSpec);
+          rv = mailUrl->SetSpec(urlSpec);
+          NS_ENSURE_SUCCESS(rv, rv);
           if (aFileName)
             mailUrl->SetFileName(nsDependentCString(aFileName));
         }
         rv =  FetchMimePart(imapUrl, nsIImapUrl::nsImapOpenMimePart, folder, imapMessageSink,
                             nsnull, aDisplayConsumer, msgKey, uriMimePart);
       }
     } // if we got a message sink
   } // if we parsed the message uri
@@ -613,25 +614,26 @@ nsresult nsImapService::FetchMimePart(ns
     aImapMailFolder->HasMsgOffline(atoi(nsCString(messageIdentifierList).get()), &useLocalCache);
     msgurl->SetMsgIsInLocalCache(useLocalCache);
   }
   rv = aImapUrl->SetImapMessageSink(aImapMessage);
   if (NS_SUCCEEDED(rv))
   {
     nsCOMPtr<nsIURI> url = do_QueryInterface(aImapUrl);
     url->GetSpec(urlSpec);
-    
+
     // rhp: If we are displaying this message for the purpose of printing, we
     // need to append the header=print option.
     //
     if (mPrintingOperation)
       urlSpec.Append("?header=print");
-    
+
     rv = url->SetSpec(urlSpec);
-    
+    NS_ENSURE_SUCCESS(rv, rv);
+
     rv = aImapUrl->SetImapAction(actionToUse /* nsIImapUrl::nsImapMsgFetch */);
     if (aImapMailFolder && aDisplayConsumer)
     {
       nsCOMPtr<nsIMsgIncomingServer> aMsgIncomingServer;
       rv = aImapMailFolder->GetServer(getter_AddRefs(aMsgIncomingServer));
       if (NS_SUCCEEDED(rv) && aMsgIncomingServer)
       {
         bool interrupted;
@@ -1385,16 +1387,17 @@ nsresult nsImapService::CreateStartOfIma
 
     nsCAutoString portStr;
     portStr.AppendInt(port);
     urlSpec.Append(portStr);
 
     // *** jefft - force to parse the urlSpec in order to search for
     // the correct incoming server
     rv = mailnewsUrl->SetSpec(urlSpec);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     hierarchyDelimiter = kOnlineHierarchySeparatorUnknown;
     nsCOMPtr <nsIMsgImapMailFolder> imapFolder = do_QueryInterface(aImapMailFolder);
     if (imapFolder)
       imapFolder->GetHierarchyDelimiter(&hierarchyDelimiter);
   }
   return rv;
 }
--- a/mailnews/local/src/nsMailboxService.cpp
+++ b/mailnews/local/src/nsMailboxService.cpp
@@ -88,17 +88,18 @@ nsresult nsMailboxService::ParseMailbox(
     nsCAutoString buf;
     MsgEscapeURL(mailboxPath,
                  nsINetUtil::ESCAPE_URL_MINIMAL | nsINetUtil::ESCAPE_URL_FORCED, buf);
     nsEscapeNativePath(buf);
     url->SetUpdatingFolder(true);
     url->SetMsgWindow(aMsgWindow);
     nsCAutoString uriSpec("mailbox://");
     uriSpec.Append(buf);
-    url->SetSpec(uriSpec);
+    rv = url->SetSpec(uriSpec);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     mailboxurl->SetMailboxParser(aMailboxParser);
     if (aUrlListener)
       url->RegisterListener(aUrlListener);
 
     rv = RunMailboxUrl(url, nsnull);
     NS_ENSURE_SUCCESS(rv, rv);
 
@@ -509,17 +510,19 @@ nsresult nsMailboxService::PrepareMessag
       else if (part)
         urlSpec = PR_smprintf("mailbox://%s?number=%lu&%s", buf.get(), msgKey, part);
       else if (header)
         urlSpec = PR_smprintf("mailbox://%s?number=%lu&%s", buf.get(), msgKey, header);
       else
         urlSpec = PR_smprintf("mailbox://%s?number=%lu", buf.get(), msgKey);
 
       nsCOMPtr <nsIMsgMailNewsUrl> url = do_QueryInterface(*aMailboxUrl);
-      url->SetSpec(nsDependentCString(urlSpec));
+      rv = url->SetSpec(nsDependentCString(urlSpec));
+      NS_ENSURE_SUCCESS(rv, rv);
+
       PR_smprintf_free(urlSpec);
 
       (*aMailboxUrl)->SetMailboxAction(aMailboxAction);
 
       // set up the url listener
       if (aUrlListener)
         rv = url->RegisterListener(aUrlListener);
 
@@ -581,24 +584,24 @@ NS_IMETHODIMP nsMailboxService::NewURI(c
   nsCOMPtr<nsIURI> aMsgUri = do_CreateInstance(NS_MAILBOXURL_CONTRACTID, &rv);
 
   if (NS_SUCCEEDED(rv))
   {
     if (aBaseURI)
     {
       nsCAutoString newSpec;
       rv = aBaseURI->Resolve(aSpec, newSpec);
-      if (NS_FAILED(rv))
-        return rv;
-      aMsgUri->SetSpec(newSpec);
+      NS_ENSURE_SUCCESS(rv, rv);
+      rv = aMsgUri->SetSpec(newSpec);
     }
     else
     {
-      aMsgUri->SetSpec(aSpec);
+      rv = aMsgUri->SetSpec(aSpec);
     }
+    NS_ENSURE_SUCCESS(rv, rv);
     aMsgUri.swap(*_retval);
   }
 
   return rv;
 }
 
 NS_IMETHODIMP nsMailboxService::NewChannel(nsIURI *aURI, nsIChannel **_retval)
 {
--- a/mailnews/news/src/nsNntpService.cpp
+++ b/mailnews/news/src/nsNntpService.cpp
@@ -890,54 +890,53 @@ nsNntpService::GetNntpServerByAccount(co
 }
 
 NS_IMETHODIMP
 nsNntpService::PostMessage(nsIFile *aFileToPost, const char *newsgroupsNames, const char *aAccountKey, nsIUrlListener * aUrlListener, nsIMsgWindow *aMsgWindow, nsIURI **_retval)
 {
   // aMsgWindow might be null
   NS_ENSURE_ARG_POINTER(newsgroupsNames);
 
-  if (*newsgroupsNames == '\0') return NS_ERROR_INVALID_ARG;
+  NS_ENSURE_ARG(*newsgroupsNames);
 
   NS_LOCK_INSTANCE();
 
   nsresult rv;
 
   nsCOMPtr <nsINntpUrl> nntpUrl = do_CreateInstance(NS_NNTPURL_CONTRACTID, &rv);
-  NS_ENSURE_SUCCESS(rv,rv);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   rv = nntpUrl->SetNewsAction(nsINntpUrl::ActionPostArticle);
-  NS_ENSURE_SUCCESS(rv,rv);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   nsCString newsUrlSpec;
   rv = SetUpNntpUrlForPosting(aAccountKey, getter_Copies(newsUrlSpec));
-  NS_ENSURE_SUCCESS(rv,rv);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(nntpUrl, &rv);
-  NS_ENSURE_SUCCESS(rv,rv);
-  if (!mailnewsurl) return NS_ERROR_FAILURE;
+  NS_ENSURE_SUCCESS(rv, rv);
 
-  mailnewsurl->SetSpec(newsUrlSpec);
+  rv = mailnewsurl->SetSpec(newsUrlSpec);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   if (aUrlListener) // register listener if there is one...
     mailnewsurl->RegisterListener(aUrlListener);
 
-  nsCOMPtr <nsINNTPNewsgroupPost> post = do_CreateInstance(NS_NNTPNEWSGROUPPOST_CONTRACTID, &rv);
-  NS_ENSURE_SUCCESS(rv,rv);
-  if (!post) return NS_ERROR_FAILURE;
+  nsCOMPtr<nsINNTPNewsgroupPost> post = do_CreateInstance(NS_NNTPNEWSGROUPPOST_CONTRACTID, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   rv = post->SetPostMessageFile(aFileToPost);
-  NS_ENSURE_SUCCESS(rv,rv);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   rv = nntpUrl->SetMessageToPost(post);
-  NS_ENSURE_SUCCESS(rv,rv);
+  NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr <nsIURI> url = do_QueryInterface(nntpUrl);
+  nsCOMPtr<nsIURI> url = do_QueryInterface(nntpUrl);
   rv = RunNewsUrl(url, aMsgWindow, nsnull /* consumer */);
-  NS_ENSURE_SUCCESS(rv,rv);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   if (_retval)
     rv = CallQueryInterface(nntpUrl, _retval);
 
   NS_UNLOCK_INSTANCE();
 
   return rv;
 }
@@ -949,17 +948,18 @@ nsNntpService::ConstructNntpUrl(const ch
 
   nsCOMPtr <nsINntpUrl> nntpUrl = do_CreateInstance(NS_NNTPURL_CONTRACTID,&rv);
   NS_ENSURE_SUCCESS(rv,rv);
 
   nsCOMPtr <nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(nntpUrl);
   mailnewsurl->SetMsgWindow(aMsgWindow);
   nsCOMPtr <nsIMsgMessageUrl> msgUrl = do_QueryInterface(nntpUrl);
   msgUrl->SetUri(originalMessageUri);
-  mailnewsurl->SetSpec(nsDependentCString(urlString));
+  rv = mailnewsurl->SetSpec(nsDependentCString(urlString));
+  NS_ENSURE_SUCCESS(rv, rv);
   nntpUrl->SetNewsAction(action);
 
   if (originalMessageUri)
   {
     // we'll use this later in nsNNTPProtocol::ParseURL()
     rv = msgUrl->SetOriginalSpec(originalMessageUri);
     NS_ENSURE_SUCCESS(rv,rv);
   }