# HG changeset patch # User alta88@gmail.com # Date 1506539725 21600 # Wed Sep 27 13:15:25 2017 -0600 # Node ID 8b61c0301de7c1e6cfbb1084b412683783d40f4d # Parent 07d4556584b96c0a5e79e3b37cf2cdaa52d29b88 Bug 1385573 - Part 1: Fix crash in nsMsgDBView::UpdateDisplayMessage. r=jorgk diff --git a/mailnews/base/src/nsMsgDBView.cpp b/mailnews/base/src/nsMsgDBView.cpp --- a/mailnews/base/src/nsMsgDBView.cpp +++ b/mailnews/base/src/nsMsgDBView.cpp @@ -1174,63 +1174,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 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 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 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 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 messenger (do_QueryReferent(mMessengerWeak)); NS_ENSURE_TRUE(messenger, NS_ERROR_FAILURE); @@ -2669,17 +2667,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) @@ -5682,16 +5680,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 msgHdr;