Bug 1732549 - fix Crash using newsgroup after View > Threads > Unread. r=benc a=wsmwk
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Mon, 27 Sep 2021 11:35:11 +0300
changeset 43457 aafe89f8ddb94f1f82553089f6ca150bc474924c
parent 43456 9c8982599ed74ce1c6d43323d14411dbf64fa143
child 43458 2408a3e26a23a1fff4b9a34565048c5862b2ad50
push id40
push userthunderbird@calypsoblue.org
push dateMon, 18 Oct 2021 19:31:13 +0000
treeherdercomm-esr91@34cfa1f3914b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbenc, wsmwk
bugs1732549
Bug 1732549 - fix Crash using newsgroup after View > Threads > Unread. r=benc a=wsmwk Differential Revision: https://phabricator.services.mozilla.com/D126638
mailnews/base/src/nsMsgGroupThread.cpp
mailnews/base/src/nsMsgXFViewThread.cpp
mailnews/db/msgdb/src/nsMsgThread.cpp
--- a/mailnews/base/src/nsMsgGroupThread.cpp
+++ b/mailnews/base/src/nsMsgGroupThread.cpp
@@ -599,38 +599,36 @@ nsresult nsMsgGroupThread::GetChildHdrFo
   if (resultIndex) *resultIndex = (int32_t)childIndex;
 
   return rv;
 }
 
 NS_IMETHODIMP nsMsgGroupThread::GetFirstUnreadChild(nsIMsgDBHdr** result) {
   NS_ENSURE_ARG_POINTER(result);
 
-  nsresult rv = NS_OK;
-
   uint32_t numChildren = 0;
   GetNumChildren(&numChildren);
 
   for (uint32_t childIndex = 0; childIndex < numChildren; childIndex++) {
     nsCOMPtr<nsIMsgDBHdr> child;
-    rv = GetChildHdrAt(childIndex, getter_AddRefs(child));
+    nsresult rv = GetChildHdrAt(childIndex, getter_AddRefs(child));
     if (NS_SUCCEEDED(rv) && child) {
       nsMsgKey msgKey;
       child->GetMessageKey(&msgKey);
 
       bool isRead;
       rv = m_db->IsRead(msgKey, &isRead);
       if (NS_SUCCEEDED(rv) && !isRead) {
         child.forget(result);
         break;
       }
     }
   }
 
-  return rv;
+  return (*result) ? NS_OK : NS_ERROR_NULL_POINTER;
 }
 
 NS_IMETHODIMP nsMsgGroupThread::GetNewestMsgDate(uint32_t* aResult) {
   NS_ENSURE_ARG_POINTER(aResult);
 
   // if this hasn't been set, figure it out by enumerating the msgs in the
   // thread.
   if (!m_newestMsgDate) {
--- a/mailnews/base/src/nsMsgXFViewThread.cpp
+++ b/mailnews/base/src/nsMsgXFViewThread.cpp
@@ -407,42 +407,40 @@ nsMsgXFViewThread::MarkChildRead(bool aR
   ChangeUnreadChildCount(aRead ? -1 : 1);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgXFViewThread::GetFirstUnreadChild(nsIMsgDBHdr** aResult) {
   NS_ENSURE_ARG(aResult);
   uint32_t numChildren;
-  nsresult rv = NS_OK;
-
   GetNumChildren(&numChildren);
 
   if ((int32_t)numChildren < 0) numChildren = 0;
 
   for (uint32_t childIndex = 0; childIndex < numChildren; childIndex++) {
     nsCOMPtr<nsIMsgDBHdr> child;
-    rv = GetChildHdrAt(childIndex, getter_AddRefs(child));
+    nsresult rv = GetChildHdrAt(childIndex, getter_AddRefs(child));
     if (NS_SUCCEEDED(rv) && child) {
       nsMsgKey msgKey;
       child->GetMessageKey(&msgKey);
 
       bool isRead;
       nsCOMPtr<nsIMsgDatabase> db;
       nsresult rv = m_folders[childIndex]->GetMsgDatabase(getter_AddRefs(db));
       if (NS_SUCCEEDED(rv)) rv = db->IsRead(msgKey, &isRead);
 
       if (NS_SUCCEEDED(rv) && !isRead) {
         child.forget(aResult);
         break;
       }
     }
   }
 
-  return rv;
+  return (*aResult) ? NS_OK : NS_ERROR_NULL_POINTER;
 }
 
 NS_IMETHODIMP
 nsMsgXFViewThread::EnumerateMessages(nsMsgKey aParentKey,
                                      nsIMsgEnumerator** aResult) {
   NS_ERROR("shouldn't call this");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
--- a/mailnews/db/msgdb/src/nsMsgThread.cpp
+++ b/mailnews/db/msgdb/src/nsMsgThread.cpp
@@ -973,27 +973,26 @@ nsresult nsMsgThread::GetChildHdrForKey(
   if (resultIndex) *resultIndex = (int32_t)childIndex;
 
   return rv;
 }
 
 NS_IMETHODIMP nsMsgThread::GetFirstUnreadChild(nsIMsgDBHdr** result) {
   NS_ENSURE_ARG_POINTER(result);
 
-  nsresult rv = NS_OK;
   uint8_t minLevel = 0xff;
 
   uint32_t numChildren = 0;
   GetNumChildren(&numChildren);
 
   nsCOMPtr<nsIMsgDBHdr> retHdr;
 
   for (uint32_t childIndex = 0; childIndex < numChildren; childIndex++) {
     nsCOMPtr<nsIMsgDBHdr> child;
-    rv = GetChildHdrAt(childIndex, getter_AddRefs(child));
+    nsresult rv = GetChildHdrAt(childIndex, getter_AddRefs(child));
     if (NS_SUCCEEDED(rv) && child) {
       nsMsgKey msgKey;
       child->GetMessageKey(&msgKey);
 
       bool isRead;
       rv = m_mdbDB->IsRead(msgKey, &isRead);
       if (NS_SUCCEEDED(rv) && !isRead) {
         // this is the root, so it's the best we're going to do.
@@ -1017,17 +1016,17 @@ NS_IMETHODIMP nsMsgThread::GetFirstUnrea
           minLevel = level;
           retHdr = child;
         }
       }
     }
   }
 
   retHdr.forget(result);
-  return rv;
+  return (*result) ? NS_OK : NS_ERROR_NULL_POINTER;
 }
 
 NS_IMETHODIMP nsMsgThread::GetNewestMsgDate(uint32_t* aResult) {
   // if this hasn't been set, figure it out by enumerating the msgs in the
   // thread.
   if (!m_newestMsgDate) {
     nsresult rv;
     uint32_t numChildren;