Bug 1385573 - Part 1: Fix crash in nsMsgDBView::UpdateDisplayMessage. r=jorgk
authoralta88@gmail.com
Wed, 27 Sep 2017 13:15:25 -0600
changeset 29102 8b61c0301de7c1e6cfbb1084b412683783d40f4d
parent 29101 5cdc0ea5bca13052da73309aaad97f06c158c493
child 29103 40f5ba35583e4f0c0ebcb06b9ea9444b38104806
push id2068
push userclokep@gmail.com
push dateMon, 13 Nov 2017 19:02:14 +0000
treeherdercomm-beta@9c7e7ce8672b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorgk
bugs1385573
Bug 1385573 - Part 1: Fix crash in nsMsgDBView::UpdateDisplayMessage. r=jorgk
mailnews/base/src/nsMsgDBView.cpp
--- a/mailnews/base/src/nsMsgDBView.cpp
+++ b/mailnews/base/src/nsMsgDBView.cpp
@@ -1144,63 +1144,61 @@ nsMsgDBView::ReloadMessage()
 
   UpdateDisplayMessage(m_currentlyDisplayedViewIndex);
   return NS_OK;
 }
 
 nsresult
 nsMsgDBView::UpdateDisplayMessage(nsMsgViewIndex viewPosition)
 {
+  if (!mCommandUpdater)
+    return NS_OK;
+
+  if (!IsValidIndex(viewPosition))
+    return NS_MSG_INVALID_DBVIEW_INDEX;
+
+  // Get the subject and the folder for the message and inform the front
+  // end that we changed the message we are currently displaying.
   nsresult rv;
-  if (mCommandUpdater)
-  {
-    // Get the subject and the folder for the message and inform the front
-    // end that we changed the message we are currently displaying.
-    if (viewPosition != nsMsgViewIndex_None)
-    {
-      nsCOMPtr <nsIMsgDBHdr> msgHdr;
-      rv = GetMsgHdrForViewIndex(viewPosition, getter_AddRefs(msgHdr));
-      NS_ENSURE_SUCCESS(rv,rv);
-
-      nsString subject;
-      FetchSubject(msgHdr, m_flags[viewPosition], subject);
-
-      nsCString keywords;
-      rv = msgHdr->GetStringProperty("keywords", getter_Copies(keywords));
-      NS_ENSURE_SUCCESS(rv,rv);
-
-      nsCOMPtr<nsIMsgFolder> folder = m_viewFolder ? m_viewFolder : m_folder;
-
-      mCommandUpdater->DisplayMessageChanged(folder, subject, keywords);
-
-      if (folder)
-      {
-        rv = folder->SetLastMessageLoaded(m_keys[viewPosition]);
-        NS_ENSURE_SUCCESS(rv,rv);
-      }
-    } // if view position is valid
-  } // if we have an updater
+  nsCOMPtr <nsIMsgDBHdr> msgHdr;
+  rv = GetMsgHdrForViewIndex(viewPosition, getter_AddRefs(msgHdr));
+  NS_ENSURE_SUCCESS(rv,rv);
+
+  nsString subject;
+  FetchSubject(msgHdr, m_flags[viewPosition], subject);
+
+  nsCString keywords;
+  rv = msgHdr->GetStringProperty("keywords", getter_Copies(keywords));
+  NS_ENSURE_SUCCESS(rv,rv);
+
+  nsCOMPtr<nsIMsgFolder> folder = m_viewFolder ? m_viewFolder : m_folder;
+
+  mCommandUpdater->DisplayMessageChanged(folder, subject, keywords);
+
+  if (folder)
+  {
+    rv = folder->SetLastMessageLoaded(m_keys[viewPosition]);
+    NS_ENSURE_SUCCESS(rv,rv);
+  }
 
   return NS_OK;
 }
 
 // Given a msg key, we will load the message for it.
 NS_IMETHODIMP
 nsMsgDBView::LoadMessageByMsgKey(nsMsgKey aMsgKey)
 {
   return LoadMessageByViewIndex(FindKey(aMsgKey, false));
 }
 
 NS_IMETHODIMP
 nsMsgDBView::LoadMessageByViewIndex(nsMsgViewIndex aViewIndex)
 {
-  NS_ASSERTION(aViewIndex != nsMsgViewIndex_None,
-               "trying to load nsMsgViewIndex_None");
-  if (aViewIndex == nsMsgViewIndex_None)
-    return NS_ERROR_UNEXPECTED;
+  if (!IsValidIndex(aViewIndex))
+    return NS_MSG_INVALID_DBVIEW_INDEX;
 
   nsCString uri;
   nsresult rv = GetURIForViewIndex(aViewIndex, uri);
   if (!mSuppressMsgDisplay && !m_currentlyDisplayedMsgUri.Equals(uri))
   {
     NS_ENSURE_SUCCESS(rv,rv);
     nsCOMPtr<nsIMessenger> messenger (do_QueryReferent(mMessengerWeak));
     NS_ENSURE_TRUE(messenger, NS_ERROR_FAILURE);
@@ -2639,17 +2637,17 @@ nsMsgDBView::SetSuppressMsgDisplay(bool 
     forceDisplay = true;
 
   mSuppressMsgDisplay = aSuppressDisplay;
   if (forceDisplay)
   {
     // Get the view indexfor the currently selected message.
     nsMsgViewIndex viewIndex;
     nsresult rv = GetViewIndexForFirstSelectedMsg(&viewIndex);
-    if (NS_SUCCEEDED(rv) && viewIndex != nsMsgViewIndex_None)
+    if (NS_SUCCEEDED(rv))
       LoadMessageByViewIndex(viewIndex);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgDBView::GetSuppressMsgDisplay(bool * aSuppressDisplay)
@@ -5657,16 +5655,19 @@ nsMsgDBView::ExpandAndSelectThread()
   NS_ENSURE_SUCCESS(rv,rv);
   return NS_OK;
 }
 
 nsresult
 nsMsgDBView::ExpandAndSelectThreadByIndex(nsMsgViewIndex index,
                                           bool augment)
 {
+  if (!IsValidIndex(index))
+    return NS_MSG_INVALID_DBVIEW_INDEX;
+
   nsresult rv;
 
   nsMsgViewIndex threadIndex;
   bool inThreadedMode = (m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay);
 
   if (inThreadedMode)
   {
     nsCOMPtr<nsIMsgDBHdr> msgHdr;