Bug 1732549 - fix Crash using newsgroup after View > Threads > Unread. r=benc
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Mon, 27 Sep 2021 11:35:11 +0300
changeset 33896 bd04c2bb4b2d4d64deebb818a9df977a91ab08d3
parent 33895 2cc1b940b4bf5a5f68c15a75130eb439c1edfadc
child 33897 d83e30472c119f6319aace5a40f82f4acecafae5
push id19210
push usermkmelin@iki.fi
push dateWed, 29 Sep 2021 09:52:30 +0000
treeherdercomm-central@d83e30472c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbenc
bugs1732549
Bug 1732549 - fix Crash using newsgroup after View > Threads > Unread. r=benc 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;