Bug 793865 - return error if GetOid() failed in nsMsgDatabase. r=irving
authoraceman <acelists@atlas.sk>
Mon, 01 Dec 2014 14:12:00 +0100
changeset 21464 37bc8ee327c67b32cb63fdae536d359287e5fcd4
parent 21463 34afccc6f8f755638c6fe79ed257a34df37a8050
child 21465 6025c959d8a7670e6b13147d17f6861804159331
push id1305
push usermbanner@mozilla.com
push dateMon, 23 Feb 2015 19:48:12 +0000
treeherdercomm-beta@3ae4f13858fd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersirving
bugs793865
Bug 793865 - return error if GetOid() failed in nsMsgDatabase. r=irving
mailnews/db/msgdb/src/nsMailDatabase.cpp
mailnews/db/msgdb/src/nsMsgDatabase.cpp
--- a/mailnews/db/msgdb/src/nsMailDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsMailDatabase.cpp
@@ -396,22 +396,16 @@ nsresult nsMsgOfflineOpEnumerator::Prefe
     mDone = true;
     return NS_ERROR_FAILURE;
   }
   if (NS_FAILED(rv)) 
   {
     mDone = true;
     return rv;
   }
-  // Get key from row.
-  mdbOid outOid;
-  nsMsgKey key = 0;
-  // TODO: Is the key variable unused?
-  if (NS_SUCCEEDED(offlineOpRow->GetOid(mDB->GetEnv(), &outOid)))
-    key = outOid.mOid_Id;
 
   nsIMsgOfflineImapOperation *op = new nsMsgOfflineImapOperation(mDB, offlineOpRow);
   mResultOp = op;
   if (!op)
     return NS_ERROR_OUT_OF_MEMORY;
 
   if (mResultOp) 
   {
--- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp
@@ -2382,21 +2382,21 @@ NS_IMETHODIMP nsMsgDatabase::SetStringPr
     return NS_MSG_MESSAGE_NOT_FOUND; // XXX return rv?
   return SetStringPropertyByHdr(msgHdr, aProperty, aValue);
 }
 
 NS_IMETHODIMP nsMsgDatabase::SetStringPropertyByHdr(nsIMsgDBHdr *msgHdr, const char *aProperty, const char *aValue)
 {
   // don't do notifications if message not yet added to database.
   // Ignore errors (consequences of failure are minor).
-  bool notify = true;  
-  nsMsgKey key = -1;
+  bool notify = true;
+  nsMsgKey key = nsMsgKey_None;
   msgHdr->GetMessageKey(&key);
   ContainsKey(key, &notify);
-  
+
   nsCString oldValue;
   nsresult rv = msgHdr->GetStringProperty(aProperty, getter_Copies(oldValue));
   NS_ENSURE_SUCCESS(rv,rv);
 
   // if no change to this string property, bail out
   if (oldValue.Equals(aValue))
     return NS_OK;
 
@@ -2904,27 +2904,30 @@ nsresult nsMsgDBEnumerator::PrefetchNext
     }
     if (NS_FAILED(rv))
     {
       mDone = true;
       return rv;
     }
     //Get key from row
     mdbOid outOid;
-    nsMsgKey key = 0;
-    if (NS_SUCCEEDED(hdrRow->GetOid(mDB->GetEnv(), &outOid)))
-      key = outOid.mOid_Id;
+    nsMsgKey key = nsMsgKey_None;
+    rv = hdrRow->GetOid(mDB->GetEnv(), &outOid);
+    if (NS_WARN_IF(NS_FAILED(rv)))
+      return rv;
+    key = outOid.mOid_Id;
 
     rv = mDB->GetHdrFromUseCache(key, getter_AddRefs(mResultHdr));
     if (NS_SUCCEEDED(rv) && mResultHdr)
       hdrRow->Release();
-    else
+    else {
       rv = mDB->CreateMsgHdr(hdrRow, key, getter_AddRefs(mResultHdr));
-    if (NS_FAILED(rv))
-      return rv;
+      if (NS_WARN_IF(NS_FAILED(rv)))
+        return rv;
+    }
 
     if (mResultHdr)
       mResultHdr->GetFlags(&flags);
     else
       flags = 0;
   }
   while (mFilter && NS_FAILED(mFilter(mResultHdr, mClosure)) && !(flags & nsMsgMessageFlags::Expunged));
 
@@ -4376,20 +4379,22 @@ nsIMsgThread *  nsMsgDatabase::GetThread
   if (m_mdbStore)
   {
     nsresult result = m_mdbStore->FindRow(GetEnv(), m_threadRowScopeToken,
       m_threadSubjectColumnToken, &subjectYarn,  &outRowId, getter_AddRefs(threadRow));
     if (NS_SUCCEEDED(result) && threadRow)
     {
       //Get key from row
       mdbOid outOid;
-      nsMsgKey key = 0;
+      nsMsgKey key = nsMsgKey_None;
       if (NS_SUCCEEDED(threadRow->GetOid(GetEnv(), &outOid)))
         key = outOid.mOid_Id;
       // find thread header for header whose message id we matched.
+      // It is fine if key was not found,
+      // GetThreadForThreadId(nsMsgKey_None) returns nullptr.
       thread = GetThreadForThreadId(key);
     }
 #ifdef DEBUG_bienvenu1
     else
     {
       nsresult  rv;
       nsRefPtr<nsMsgThread> pThread;
 
@@ -4580,24 +4585,30 @@ NS_IMETHODIMP nsMsgDatabase::GetMsgHdrFo
       m_messageIdColumnToken, &messageIdYarn,  &outRowId,
       &hdrRow);
   else
     return NS_ERROR_FAILURE;
   if (NS_SUCCEEDED(result) && hdrRow)
   {
     //Get key from row
     mdbOid outOid;
-    nsMsgKey key = 0;
-    if (NS_SUCCEEDED(hdrRow->GetOid(GetEnv(), &outOid)))
-      key = outOid.mOid_Id;
+    nsMsgKey key = nsMsgKey_None;
+    rv = hdrRow->GetOid(GetEnv(), &outOid);
+    if (NS_WARN_IF(NS_FAILED(rv)))
+      return rv;
+    key = outOid.mOid_Id;
+
     rv = GetHdrFromUseCache(key, &msgHdr);
     if (NS_SUCCEEDED(rv) && msgHdr)
       hdrRow->Release();
-    else
+    else {
       rv = CreateMsgHdr(hdrRow, key, &msgHdr);
+      if (NS_WARN_IF(NS_FAILED(rv)))
+        return rv;
+    }
   }
   *aHdr = msgHdr; // already addreffed above.
   return NS_OK; // it's not an error not to find a msg hdr.
 }
 
 NS_IMETHODIMP nsMsgDatabase::GetMsgHdrForGMMsgID(const char *aGMMsgId, nsIMsgDBHdr **aHdr)
 {
   NS_ENSURE_ARG_POINTER(aGMMsgId);
@@ -4625,18 +4636,21 @@ NS_IMETHODIMP nsMsgDatabase::GetMsgHdrFo
     // Get key from row
     mdbOid outOid;
     rv = hdrRow->GetOid(GetEnv(), &outOid);
     NS_ENSURE_SUCCESS(rv, rv);
     nsMsgKey key = outOid.mOid_Id;
     rv = GetHdrFromUseCache(key, &msgHdr);
     if ((NS_SUCCEEDED(rv) && msgHdr))
       hdrRow->Release();
-    else
+    else {
       rv = CreateMsgHdr(hdrRow, key, &msgHdr);
+      if (NS_WARN_IF(NS_FAILED(rv)))
+        return rv;
+    }
   }
   *aHdr = msgHdr;
   return NS_OK; // it's not an error not to find a msg hdr.
 }
 
 nsIMsgDBHdr *nsMsgDatabase::GetMsgHdrForSubject(nsCString &subject)
 {
   nsIMsgDBHdr *msgHdr = nullptr;
@@ -4652,24 +4666,30 @@ nsIMsgDBHdr *nsMsgDatabase::GetMsgHdrFor
   mdbOid outRowId;
   nsresult result = GetStore()->FindRow(GetEnv(), m_hdrRowScopeToken,
     m_subjectColumnToken, &subjectYarn,  &outRowId,
     &hdrRow);
   if (NS_SUCCEEDED(result) && hdrRow)
   {
     //Get key from row
     mdbOid outOid;
-    nsMsgKey key = 0;
-    if (NS_SUCCEEDED(hdrRow->GetOid(GetEnv(), &outOid)))
-      key = outOid.mOid_Id;
+    nsMsgKey key = nsMsgKey_None;
+    rv = hdrRow->GetOid(GetEnv(), &outOid);
+    if (NS_WARN_IF(NS_FAILED(rv)))
+      return nullptr;
+    key = outOid.mOid_Id;
+
     rv = GetHdrFromUseCache(key, &msgHdr);
     if (NS_SUCCEEDED(rv) && msgHdr)
       hdrRow->Release();
-    else
+    else {
       rv = CreateMsgHdr(hdrRow, key, &msgHdr);
+      if (NS_WARN_IF(NS_FAILED(rv)))
+        return nullptr;
+    }
   }
   return msgHdr;
 }
 
 NS_IMETHODIMP nsMsgDatabase::GetThreadContainingMsgHdr(nsIMsgDBHdr *msgHdr, nsIMsgThread **result)
 {
   NS_ENSURE_ARG_POINTER(msgHdr);
   NS_ENSURE_ARG_POINTER(result);
@@ -4750,17 +4770,17 @@ nsresult nsMsgDatabase::AddNewThread(nsM
     return NS_ERROR_NULL_POINTER;
 
   nsMsgThread *threadHdr = nullptr;
 
   nsCString subject;
   nsMsgKey threadKey = msgHdr->m_messageKey;
   // can't have a thread with key 1 since that's the table id of the all msg hdr table,
   // so give it kTableKeyForThreadOne (0xfffffffe).
-  if (threadKey == 1)
+  if (threadKey == kAllMsgHdrsTableKey)
     threadKey = kTableKeyForThreadOne;
 
   nsresult err = msgHdr->GetSubject(getter_Copies(subject));
 
   err = CreateNewThread(threadKey, subject.get(), &threadHdr);
   msgHdr->SetThreadId(threadKey);
   if (threadHdr)
   {