Bug 779130 - Add lots of static_cast<nsresult>; r=standard8
authorAryeh Gregor <ayg@aryeh.name>
Mon, 06 Aug 2012 18:49:44 +0300
changeset 13279 4e6feae89ab41b6e6b2a2b00f1924c78aa453f76
parent 13278 9354cabcfa4145c983bb5adcbe3feec9a4daccd7
child 13280 eb4e923be691c8e2058897d8e8b2aa388cee4105
push idunknown
push userunknown
push dateunknown
reviewersstandard8
bugs779130
Bug 779130 - Add lots of static_cast<nsresult>; r=standard8
db/mork/src/morkCursor.cpp
db/mork/src/morkNode.cpp
db/mork/src/morkObject.cpp
db/mork/src/morkStore.cpp
db/mork/src/morkZone.cpp
mailnews/addrbook/src/nsAbLDAPReplicationData.cpp
mailnews/addrbook/src/nsAbMDBDirectory.cpp
mailnews/base/search/src/nsMsgFilter.cpp
mailnews/compose/src/nsMsgSend.cpp
mailnews/compose/src/nsMsgSendPart.cpp
mailnews/compose/src/nsSmtpProtocol.cpp
mailnews/extensions/smime/src/nsMsgComposeSecure.cpp
mailnews/imap/src/nsIMAPHostSessionList.cpp
mailnews/local/src/nsPop3Protocol.cpp
mailnews/mime/emitters/src/nsMimeBaseEmitter.cpp
mailnews/mime/src/mimemoz2.cpp
mailnews/mime/src/nsMimeHeaders.cpp
mailnews/mime/src/nsStreamConverter.cpp
mailnews/news/src/nsNNTPNewsgroupList.cpp
--- a/db/mork/src/morkCursor.cpp
+++ b/db/mork/src/morkCursor.cpp
@@ -94,33 +94,37 @@ morkCursor::GetStrongRefCount(nsIMdbEnv*
 {
   *outCount = StrongRefsOnly();
   return NS_OK;
 }
 // ### TODO - clean up this cast, if required
 NS_IMETHODIMP
 morkCursor::AddWeakRef(nsIMdbEnv* mev)
 {
-  return morkNode::AddWeakRef((morkEnv *) mev);
+  // XXX Casting mork_refs to nsresult
+  return static_cast<nsresult>(morkNode::AddWeakRef((morkEnv *) mev));
 }
 NS_IMETHODIMP
 morkCursor::AddStrongRef(nsIMdbEnv* mev)
 {
-  return morkNode::AddStrongRef((morkEnv *) mev);
+  // XXX Casting mork_uses to nsresult
+  return static_cast<nsresult>(morkNode::AddStrongRef((morkEnv *) mev));
 }
 
 NS_IMETHODIMP
 morkCursor::CutWeakRef(nsIMdbEnv* mev)
 {
-  return morkNode::CutWeakRef((morkEnv *) mev);
+  // XXX Casting mork_refs to nsresult
+  return static_cast<nsresult>(morkNode::CutWeakRef((morkEnv *) mev));
 }
 NS_IMETHODIMP
 morkCursor::CutStrongRef(nsIMdbEnv* mev)
 {
-  return morkNode::CutStrongRef((morkEnv *) mev);
+  // XXX Casting mork_uses to nsresult
+  return static_cast<nsresult>(morkNode::CutStrongRef((morkEnv *) mev));
 }
 
   
 NS_IMETHODIMP
 morkCursor::CloseMdbObject(nsIMdbEnv* mev)
 {
   return morkNode::CloseMdbObject((morkEnv *) mev);
 }
--- a/db/mork/src/morkNode.cpp
+++ b/db/mork/src/morkNode.cpp
@@ -207,17 +207,18 @@ morkNode::CloseMdbObject(nsIMdbEnv* mev)
 {
   return morkNode::CloseMdbObject((morkEnv *) mev);
 }
 
 mdb_err morkNode::CloseMdbObject(morkEnv *ev)
 {
   // if only one ref, Handle_CutStrongRef will clean up better.
   if (mNode_Uses == 1)
-    return CutStrongRef(ev);
+    // XXX Casting mork_uses to mdb_err
+    return static_cast<mdb_err>(CutStrongRef(ev));
 
   mdb_err outErr = NS_OK;
   
   if ( IsNode() && IsOpenNode() )
   {
     if ( ev )
     {
       CloseMorkNode(ev);
--- a/db/mork/src/morkObject.cpp
+++ b/db/mork/src/morkObject.cpp
@@ -138,33 +138,37 @@ morkObject::GetStrongRefCount(nsIMdbEnv*
 {
   *outCount = StrongRefsOnly();
   return NS_OK;
 }
 // ### TODO - clean up this cast, if required
 NS_IMETHODIMP
 morkObject::AddWeakRef(nsIMdbEnv* mev)
 {
-  return morkNode::AddWeakRef((morkEnv *) mev);
+  // XXX Casting mork_refs to nsresult
+  return static_cast<nsresult>(morkNode::AddWeakRef((morkEnv *) mev));
 }
 NS_IMETHODIMP
 morkObject::AddStrongRef(nsIMdbEnv* mev)
 {
-  return morkNode::AddStrongRef((morkEnv *) mev);
+  // XXX Casting mork_uses to nsresult
+  return static_cast<nsresult>(morkNode::AddStrongRef((morkEnv *) mev));
 }
 
 NS_IMETHODIMP
 morkObject::CutWeakRef(nsIMdbEnv* mev)
 {
-  return morkNode::CutWeakRef((morkEnv *) mev);
+  // XXX Casting mork_refs to nsresult
+  return static_cast<nsresult>(morkNode::CutWeakRef((morkEnv *) mev));
 }
 NS_IMETHODIMP
 morkObject::CutStrongRef(nsIMdbEnv* mev)
 {
-  return morkNode::CutStrongRef((morkEnv *) mev);
+  // XXX Casting mork_uses to nsresult
+  return static_cast<nsresult>(morkNode::CutStrongRef((morkEnv *) mev));
 }
 
   
 NS_IMETHODIMP
 morkObject::CloseMdbObject(nsIMdbEnv* mev)
 {
   return morkNode::CloseMdbObject((morkEnv *) mev);
 }
--- a/db/mork/src/morkStore.cpp
+++ b/db/mork/src/morkStore.cpp
@@ -1305,34 +1305,38 @@ morkStore::GetStrongRefCount(nsIMdbEnv* 
   *outCount = StrongRefsOnly();
   return NS_OK;
 }
 // ### TODO - clean up this cast, if required
 NS_IMETHODIMP
 morkStore::AddWeakRef(nsIMdbEnv* mev)
 {
   morkEnv *ev  = morkEnv::FromMdbEnv(mev);
-  return morkNode::AddWeakRef(ev);
+  // XXX Casting mork_refs to nsresult
+  return static_cast<nsresult>(morkNode::AddWeakRef(ev));
 }
 NS_IMETHODIMP
 morkStore::AddStrongRef(nsIMdbEnv* mev)
 {
-  return AddRef();
+  // XXX Casting nsrefcnt to nsresult
+  return static_cast<nsresult>(AddRef());
 }
 
 NS_IMETHODIMP
 morkStore::CutWeakRef(nsIMdbEnv* mev)
 {
   morkEnv *ev  = morkEnv::FromMdbEnv(mev);
-  return morkNode::CutWeakRef(ev);
+  // XXX Casting mork_refs to nsresult
+  return static_cast<nsresult>(morkNode::CutWeakRef(ev));
 }
 NS_IMETHODIMP
 morkStore::CutStrongRef(nsIMdbEnv* mev)
 {
-  return Release();
+  // XXX Casting nsrefcnt to nsresult
+  return static_cast<nsresult>(Release());
 }
 
 NS_IMETHODIMP
 morkStore::CloseMdbObject(nsIMdbEnv* mev)
 {
   morkEnv *ev = morkEnv::FromMdbEnv(mev);
   CloseMorkNode(ev);
   Release();
--- a/db/mork/src/morkZone.cpp
+++ b/db/mork/src/morkZone.cpp
@@ -494,17 +494,18 @@ morkZone::Alloc(nsIMdbEnv* mev, // alloc
   void* block = 0;
   morkEnv* ev = morkEnv::FromMdbEnv(mev);
   if ( ev )
   {
     block = this->ZoneNewRun(ev, inSize);
     outErr = ev->AsErr();
   }
   else
-    outErr = 1;
+    // XXX 1 is not a valid mdb_err (= nsresult)
+    outErr = static_cast<mdb_err>(1);
     
   if ( outBlock )
     *outBlock = block;
     
   return outErr;
 }
   
 /*virtual*/ mdb_err
@@ -516,17 +517,18 @@ morkZone::Free(nsIMdbEnv* mev, // free b
   {
     morkEnv* ev = morkEnv::FromMdbEnv(mev);
     if ( ev )
     {
       this->ZoneZapRun(ev, inBlock);
       outErr = ev->AsErr();
     }
     else
-      outErr = 1;
+      // XXX 1 is not a valid mdb_err (= nsresult)
+      outErr = static_cast<mdb_err>(1);
   }
     
   return outErr;
 }
 
 /*virtual*/ mdb_err
 morkZone::HeapAddStrongRef(nsIMdbEnv* mev) // does nothing
 {
--- a/mailnews/addrbook/src/nsAbLDAPReplicationData.cpp
+++ b/mailnews/addrbook/src/nsAbLDAPReplicationData.cpp
@@ -201,18 +201,20 @@ nsresult nsAbLDAPProcessReplicationData:
   nsCAutoString attributes;
   rv = mDirectoryUrl->GetAttributes(attributes);
   if (NS_FAILED(rv))
     return rv;
 
   mState = kReplicatingAll;
 
   if (mListener && NS_SUCCEEDED(rv))
+    // XXX Cast from bool to nsresult
     mListener->OnStateChange(nullptr, nullptr,
-                             nsIWebProgressListener::STATE_START, true);
+                             nsIWebProgressListener::STATE_START,
+                             static_cast<nsresult>(true));
 
   return mOperation->SearchExt(dn, scope, urlFilter, attributes, 0, 0);
 }
 
 void nsAbLDAPProcessReplicationData::InitFailed(bool aCancelled)
 {
   // Just call Done() which will ensure everything is tidied up nicely.
   Done(false);
@@ -463,17 +465,20 @@ void nsAbLDAPProcessReplicationData::Don
        return;
 
    mState = kReplicationDone;
 
    if (mQuery)
      mQuery->Done(aSuccess);
 
    if (mListener)
-       mListener->OnStateChange(nullptr, nullptr, nsIWebProgressListener::STATE_STOP, aSuccess);
+       // XXX Cast from bool to nsresult
+       mListener->OnStateChange(nullptr, nullptr,
+           nsIWebProgressListener::STATE_STOP,
+           static_cast<nsresult>(aSuccess));
 
    // since this is called when all is done here, either on success,
    // failure or abort release the query now.
    mQuery = nullptr;
 }
 
 nsresult nsAbLDAPProcessReplicationData::DeleteCard(nsString & aDn)
 {
--- a/mailnews/addrbook/src/nsAbMDBDirectory.cpp
+++ b/mailnews/addrbook/src/nsAbMDBDirectory.cpp
@@ -193,17 +193,18 @@ NS_IMETHODIMP nsAbMDBDirectory::DeleteDi
   rv = database->DeleteMailList(directory, this);
 
   if (NS_SUCCEEDED(rv))
     database->Commit(nsAddrDBCommitType::kLargeCommit);
 
   PRUint32 dirIndex;
   if (m_AddressList && NS_SUCCEEDED(m_AddressList->IndexOf(0, directory, &dirIndex)))
     m_AddressList->RemoveElementAt(dirIndex);
-  rv = mSubDirectories.RemoveObject(directory);
+  // XXX Cast from bool to nsresult
+  rv = static_cast<nsresult>(mSubDirectories.RemoveObject(directory));
 
   NotifyItemDeleted(directory);
   return rv;
 }
 
 nsresult nsAbMDBDirectory::NotifyItemChanged(nsISupports *item)
 {
   nsresult rv;
--- a/mailnews/base/search/src/nsMsgFilter.cpp
+++ b/mailnews/base/search/src/nsMsgFilter.cpp
@@ -308,56 +308,61 @@ nsMsgFilter::GetSortedActionList(nsISupp
 
     nsMsgRuleActionType actionType;
     action->GetType(&actionType);
     switch (actionType)
     {
       case nsMsgFilterAction::FetchBodyFromPop3Server:
       {
         // always insert in front
-        rv = actionList->InsertElementAt(action, 0);
+        // XXX Cast from bool to nsresult
+        rv = static_cast<nsresult>(actionList->InsertElementAt(action, 0));
         NS_ENSURE_SUCCESS(rv, rv);
         ++nextIndexForNormal;
         ++nextIndexForCopy;
         ++nextIndexForMove;
         break;
       }
 
       case nsMsgFilterAction::CopyToFolder:
       {
         // insert into copy actions block, in order of appearance
-        rv = actionList->InsertElementAt(action, nextIndexForCopy);
+        // XXX Cast from bool to nsresult
+        rv = static_cast<nsresult>(actionList->InsertElementAt(action, nextIndexForCopy));
         NS_ENSURE_SUCCESS(rv, rv);
         ++nextIndexForCopy;
         ++nextIndexForMove;
         break;
       }
 
       case nsMsgFilterAction::MoveToFolder:
       case nsMsgFilterAction::Delete:
       {
         // insert into move/delete action block
-        rv = actionList->InsertElementAt(action, nextIndexForMove);
+        // XXX Cast from bool to nsresult
+        rv = static_cast<nsresult>(actionList->InsertElementAt(action, nextIndexForMove));
         NS_ENSURE_SUCCESS(rv, rv);
         ++nextIndexForMove;
         break;
       }
 
       case nsMsgFilterAction::StopExecution:
       {
         // insert into stop action block
-        rv = actionList->AppendElement(action);
+        // XXX Cast from bool to nsresult
+        rv = static_cast<nsresult>(actionList->AppendElement(action));
         NS_ENSURE_SUCCESS(rv, rv);
         break;
       }
 
       default:
       {
         // insert into normal action block, in order of appearance
-        rv = actionList->InsertElementAt(action, nextIndexForNormal);
+        // XXX Cast from bool to nsresult
+        rv = static_cast<nsresult>(actionList->InsertElementAt(action, nextIndexForNormal));
         NS_ENSURE_SUCCESS(rv, rv);
         ++nextIndexForNormal;
         ++nextIndexForCopy;
         ++nextIndexForMove;
         break;
       }
     }
   }
--- a/mailnews/compose/src/nsMsgSend.cpp
+++ b/mailnews/compose/src/nsMsgSend.cpp
@@ -2639,18 +2639,24 @@ nsMsgComposeAndSend::HackAttachments(nsI
         nsAutoString attachmentFileName;
         nsresult rv = ConvertToUnicode(nsMsgI18NFileSystemCharset(), m_attachments[i].m_realName, attachmentFileName);
         if (NS_SUCCEEDED(rv))
         {
           nsCOMPtr<nsIStringBundle> bundle;
           const PRUnichar *params[] = { attachmentFileName.get() };
           mComposeBundle->FormatStringFromID(NS_ERROR_GET_CODE(NS_MSG_ERROR_ATTACHING_FILE), params, 1, getter_Copies(errorMsg));
           mSendReport->SetMessage(nsIMsgSendReport::process_Current, errorMsg.get(), false);
-          mSendReport->SetError(nsIMsgSendReport::process_Current, NS_MSG_GENERATE_FAILURE(NS_MSG_ERROR_ATTACHING_FILE) /* status */,
-                                false);
+          mSendReport->SetError(nsIMsgSendReport::process_Current,
+              // XXX The following applies NS_ERROR_GENERATE_FAILURE twice,
+              // which doesn't make sense.  Just NS_MSG_ERROR_ATTACHING_FILE is
+              // surely what was intended.
+              NS_ERROR_GENERATE_FAILURE(
+                NS_ERROR_MODULE_MAILNEWS,
+                static_cast<PRUint32>(NS_MSG_ERROR_ATTACHING_FILE)),
+              false);
         }
         return NS_MSG_ERROR_ATTACHING_FILE;
       }
       if (m_be_synchronous_p)
         break;
     }
   }
 
--- a/mailnews/compose/src/nsMsgSendPart.cpp
+++ b/mailnews/compose/src/nsMsgSendPart.cpp
@@ -230,28 +230,30 @@ nsresult nsMsgSendPart::PushBody(const c
 {
   nsresult status = NS_OK;
   const char* encoded_data = buffer;
 
   if (m_encoder_data)
   {
     nsresult rv = MIME_EncoderWrite(m_encoder_data, encoded_data, length);
     if (NS_FAILED(rv))
-      status = -1;
+      // XXX -1 is not a valid nsresult
+      status = static_cast<nsresult>(-1);
   }
   else
   {
     // Merely translate all linebreaks to CRLF.
     const char *in = encoded_data;
     const char *end = in + length;
     char *buffer, *out;
 
 
     buffer = mime_get_stream_write_buffer();
-    NS_ENSURE_TRUE(buffer, -1);
+    // XXX -1 is not a valid nsresult
+    NS_ENSURE_TRUE(buffer, static_cast<nsresult>(-1));
 
     NS_ASSERTION(encoded_data != buffer, "encoded_data == buffer");
     out = buffer;
 
     for (; in < end; in++) {
       if (m_just_hit_CR) {
         m_just_hit_CR = false;
         if (*in == '\n') {
@@ -453,17 +455,18 @@ nsMsgSendPart::Write()
 #define PUSH(str) PUSHLEN(str, PL_strlen(str))
 
   // rhp: Suppress the output of parts that are empty!
   if ( (m_parent) &&
        (m_numchildren == 0) &&
        ( (!m_buffer) || (!*m_buffer) ) &&
        (!m_file) &&
        (!m_mainpart) )
-    return SKIP_EMPTY_PART;
+    // XXX SKIP_EMPTY_PART (= 1966) is not a valid nsresult
+    return static_cast<nsresult>(SKIP_EMPTY_PART);
 
   if (m_mainpart && m_type && PL_strcmp(m_type, TEXT_HTML) == 0) 
   {     
     if (m_file) 
     {
       // The "insert HTML links" code requires a memory buffer,
       // so read the file into memory.
       NS_ASSERTION(m_buffer == nullptr, "not-null buffer");
@@ -735,17 +738,18 @@ nsMsgSendPart::Write()
 
   if (m_encoder_data)
   {
     nsresult rv  = MIME_EncoderDestroy(m_encoder_data, false);
     m_encoder_data = nullptr;
     needToWriteCRLFAfterEncodedBody = !m_parent;
     if (NS_FAILED(rv))
     {
-      status = -1;
+      // XXX -1 is not a valid nsresult
+      status = static_cast<nsresult>(-1);
       goto FAIL;
     }
   }
 
   //
   // Ok, from here we loop and drive the the output of all children 
   // for this message.
   //
@@ -763,17 +767,18 @@ nsMsgSendPart::Write()
         PUSH(separator);
         PUSH(CRLF);
       }
 
       status = m_children[i]->Write();
       if (NS_FAILED(status))
         goto FAIL;
 
-      if (status == SKIP_EMPTY_PART)
+      // XXX SKIP_EMPTY_PART (= 1966) is not a valid nsresult
+      if (status == static_cast<nsresult>(SKIP_EMPTY_PART))
         writeSeparator = false;
       else
         writeSeparator = true;
     }
 
     PUSH(CRLF);
     PUSH("--");
     PUSH(separator);
--- a/mailnews/compose/src/nsSmtpProtocol.cpp
+++ b/mailnews/compose/src/nsSmtpProtocol.cpp
@@ -1565,17 +1565,18 @@ PRInt32 nsSmtpProtocol::SendRecipientRes
   SetFlag(SMTP_PAUSE_FOR_READ);
 
   return(status);
 }
 
 
 nsresult nsSmtpProtocol::SendData(const char *dataBuffer, bool aSuppressLogging)
 {
-  if (!dataBuffer) return -1;
+  // XXX -1 is not a valid nsresult
+  if (!dataBuffer) return static_cast<nsresult>(-1);
 
   if (!aSuppressLogging) {
       PR_LOG(SMTPLogModule, PR_LOG_ALWAYS, ("SMTP Send: %s", dataBuffer));
   } else {
       PR_LOG(SMTPLogModule, PR_LOG_ALWAYS, ("Logging suppressed for this command (it probably contained authentication information)"));
   }
   return nsMsgAsyncWriteProtocol::SendData(dataBuffer);
 }
--- a/mailnews/extensions/smime/src/nsMsgComposeSecure.cpp
+++ b/mailnews/extensions/smime/src/nsMsgComposeSecure.cpp
@@ -214,17 +214,18 @@ nsresult nsMsgComposeSecure::GetSMIMEBun
 {
   *outString = nullptr;
 
   NS_ENSURE_ARG_POINTER(name);
 
   if (!InitializeSMIMEBundle())
     return NS_ERROR_FAILURE;
 
-  return NS_SUCCEEDED(mSMIMEBundle->GetStringFromName(name, outString));
+  // XXX Cast of bool to nsresult
+  return static_cast<nsresult>(NS_SUCCEEDED(mSMIMEBundle->GetStringFromName(name, outString)));
 }
 
 nsresult
 nsMsgComposeSecure::
 SMIMEBundleFormatStringFromName(const PRUnichar *name,
                                 const PRUnichar **params,
                                 PRUint32 numParams,
                                 PRUnichar **outString)
@@ -397,17 +398,18 @@ NS_IMETHODIMP nsMsgComposeSecure::BeginC
     rv = MimeInitEncryption(true, sendReport);
     break;
   case mime_crypto_encrypted:
     rv = MimeInitEncryption(false, sendReport);
     break;
   case mime_crypto_none:
     /* This can happen if mime_crypto_hack_certs() decided to turn off
      encryption (by asking the user.) */
-    rv = 1;
+    // XXX 1 is not a valid nsresult
+    rv = static_cast<nsresult>(1);
     break;
   default:
     PR_ASSERT(0);
     break;
   }
 
 FAIL:
   return rv;
@@ -456,17 +458,18 @@ nsresult nsMsgComposeSecure::MimeInitMul
 
   L = strlen(header);
 
   if (aOuter){
     /* If this is the outer block, write it to the file. */
     PRUint32 n;
     rv = mStream->Write(header, L, &n);
     if (NS_FAILED(rv) || n < L) {
-      rv = MK_MIME_ERROR_WRITING_FILE;
+      // XXX This is -1, not an nsresult
+      rv = static_cast<nsresult>(MK_MIME_ERROR_WRITING_FILE);
     }
   } else {
     /* If this is an inner block, feed it through the crypto stream. */
     rv = MimeCryptoWriteBlock (header, L);
   }
 
   PR_Free(header);
   if (NS_FAILED(rv)) goto FAIL;
@@ -654,17 +657,18 @@ nsresult nsMsgComposeSecure::MimeFinishM
   }
 
   L = strlen(header);
   if (aOuter) {
     /* If this is the outer block, write it to the file. */
     PRUint32 n;
     rv = mStream->Write(header, L, &n);
     if (NS_FAILED(rv) || n < L) {
-      rv = MK_MIME_ERROR_WRITING_FILE;
+      // XXX This is -1, not an nsresult
+      rv = static_cast<nsresult>(MK_MIME_ERROR_WRITING_FILE);
     } 
   } else {
     /* If this is an inner block, feed it through the crypto stream. */
     rv = MimeCryptoWriteBlock (header, L);
   }
 
   PR_Free(header);
 
@@ -733,17 +737,18 @@ nsresult nsMsgComposeSecure::MimeFinishM
     goto FAIL;
   }
   L = strlen(header);
   if (aOuter) {
     /* If this is the outer block, write it to the file. */
     PRUint32 n;
     rv = mStream->Write(header, L, &n);
     if (NS_FAILED(rv) || n < L)
-      rv = MK_MIME_ERROR_WRITING_FILE;
+      // XXX This is -1, not an nsresult
+      rv = static_cast<nsresult>(MK_MIME_ERROR_WRITING_FILE);
   } else {
     /* If this is an inner block, feed it through the crypto stream. */
     rv = MimeCryptoWriteBlock (header, L);
   }
   }
 
 FAIL:
   return rv;
@@ -847,17 +852,18 @@ nsresult nsMsgComposeSecure::MimeCryptoH
   }
 
   pHeader->ExtractHeaderAddressMailboxes(nsDependentCString(aRecipients),
                                          all_mailboxes);
   pHeader->RemoveDuplicateAddresses(all_mailboxes, EmptyCString(), mailboxes);
 
   pHeader->ParseHeaderAddresses(mailboxes.get(), 0, &mailbox_list, &count);
 
-  if (count < 0) return count;
+  // XXX This is not a valid use of nsresult
+  if (count < 0) return static_cast<nsresult>(count);
 
   if (aEncrypt && mSelfEncryptionCert) {
     // Make sure self's configured cert is prepared for being used
     // as an email recipient cert.
     
     nsCOMPtr<nsISMimeCert> sc = do_QueryInterface(mSelfEncryptionCert);
     if (sc) {
       sc->SaveSMimeProfile();
@@ -937,19 +943,22 @@ NS_IMETHODIMP nsMsgComposeSecure::MimeCr
    going to cause the signature check to fail.
 
    (This assumes that, in the cases where From-mangling must happen,
    this function is called a line at a time.  That happens to be the
    case.)
   */
   if (size >= 5 && buf[0] == 'F' && !strncmp(buf, "From ", 5)) {
     char mangle[] = ">";
-    status = MimeCryptoWriteBlock (mangle, 1);
-    if (status < 0)
-    return status;
+    nsresult res = MimeCryptoWriteBlock (mangle, 1);
+    if (NS_FAILED(res))
+      return res;
+    // This value will actually be cast back to an nsresult before use, so this
+    // cast is reasonable under the circumstances.
+    status = static_cast<int>(res);
   }
 
   /* If we're signing, or signing-and-encrypting, feed this data into
    the computation of the hash. */
   if (mDataHash) {
     PR_SetError(0,0);
     mDataHash->Update((const PRUint8*) buf, size);
 	  status = PR_GetError();
@@ -988,21 +997,24 @@ NS_IMETHODIMP nsMsgComposeSecure::MimeCr
     }
   } else {
 	  /* If we're not encrypting (presumably just signing) then write this
 		 data directly to the file. */
 
     PRUint32 n;
     rv = mStream->Write(buf, size, &n);
     if (NS_FAILED(rv) || n < size) {
-      return MK_MIME_ERROR_WRITING_FILE;
+      // XXX MK_MIME_ERROR_WRITING_FILE is -1, which is not a valid nsresult
+      return static_cast<nsresult>(MK_MIME_ERROR_WRITING_FILE);
     }
   }
  FAIL:
-  return status;
+  // XXX status sometimes has invalid nsresults like -1 or PR_GetError()
+  // assigned to it
+  return static_cast<nsresult>(status);
 }
 
 /* Returns a string consisting of a Content-Type header, and a boundary
    string, suitable for moving from the header block, down into the body
    of a multipart object.  The boundary itself is also returned (so that
    the caller knows what to write to close it off.)
  */
 static nsresult
--- a/mailnews/imap/src/nsIMAPHostSessionList.cpp
+++ b/mailnews/imap/src/nsIMAPHostSessionList.cpp
@@ -658,17 +658,18 @@ NS_IMETHODIMP nsIMAPHostSessionList::Add
 	PR_EnterMonitor(gCachedHostInfoMonitor);
 	nsIMAPHostInfo *host = FindHost(serverKey);
 	if (host)
 	{
 		if (host->fShellCache)
 		{
 			bool rv = host->fShellCache->AddShellToCache(shell);
 			PR_ExitMonitor(gCachedHostInfoMonitor);
-			return rv;
+			// XXX Cast of bool to nsresult
+			return static_cast<nsresult>(rv);
 		}
 		else
 		{
 			PR_ExitMonitor(gCachedHostInfoMonitor);
 			return NS_OK;
 		}
 	}
 	PR_ExitMonitor(gCachedHostInfoMonitor);
--- a/mailnews/local/src/nsPop3Protocol.cpp
+++ b/mailnews/local/src/nsPop3Protocol.cpp
@@ -3558,17 +3558,19 @@ nsPop3Protocol::HandleLine(char *line, P
 
             // The following was added to prevent the loss of Data when we try
             // and write to somewhere we don't have write access error to (See
             // bug 62480)
             // (Note: This is only a temp hack until the underlying XPCOM is
             // fixed to return errors)
 
             if (NS_FAILED(rv))
-              return (Error((rv == NS_MSG_ERROR_COPYING_FROM_TMP_DOWNLOAD)
+              // XXX Error() returns -1, which is not a valid nsresult
+              return static_cast<nsresult>(Error(
+                             (rv == NS_MSG_ERROR_COPYING_FROM_TMP_DOWNLOAD)
                              ? POP3_TMP_DOWNLOAD_FAILED
                              : POP3_MESSAGE_WRITE_ERROR));
 
             m_pop3ConData->msg_closure = nullptr;
             return rv;
         }
     }
     /* Check if the line begins with the termination octet. If so
@@ -3724,17 +3726,18 @@ nsresult nsPop3Protocol::ProcessProtocol
   PR_LOG(POP3LOGMODULE, PR_LOG_ALWAYS, ("Entering NET_ProcessPop3 %d",
     aLength));
 
   m_pop3ConData->pause_for_read = false; /* already paused; reset */
 
   if(m_username.IsEmpty())
   {
     // net_pop3_block = false;
-    return(Error(POP3_USERNAME_UNDEFINED));
+    // XXX Error() returns -1, which is not a valid nsresult
+    return static_cast<nsresult>(Error(POP3_USERNAME_UNDEFINED));
   }
 
   while(!m_pop3ConData->pause_for_read)
   {
     PR_LOG(POP3LOGMODULE, PR_LOG_ALWAYS,
       ("POP3: Entering state: %d", m_pop3ConData->next_state));
 
     switch(m_pop3ConData->next_state)
--- a/mailnews/mime/emitters/src/nsMimeBaseEmitter.cpp
+++ b/mailnews/mime/emitters/src/nsMimeBaseEmitter.cpp
@@ -694,17 +694,19 @@ nsMimeBaseEmitter::GenerateDateString(co
 
   dateFormatPrefs->GetBoolPref("date_senders_timezone", &displaySenderTimezone);
   dateFormatPrefs->GetBoolPref("original_date", &displayOriginalDate);
   // migrate old pref to date_senders_timezone
   if (displayOriginalDate && !displaySenderTimezone)
     dateFormatPrefs->SetBoolPref("date_senders_timezone", true);
 
   PRExplodedTime explodedMsgTime;
-  rv = PR_ParseTimeStringToExplodedTime(dateString, false, &explodedMsgTime);
+  // XXX Casting PRStatus to nsresult
+  rv = static_cast<nsresult>(
+    PR_ParseTimeStringToExplodedTime(dateString, false, &explodedMsgTime));
   /**
    * To determine the date format to use, comparison of current and message
    * time has to be made. If displaying in local time, both timestamps have
    * to be in local time. If displaying in senders time zone, leave the compare
    * time in that time zone.
    * Otherwise in TZ+0100 on 2009-03-12 a message from 2009-03-11T20:49-0700
    * would be displayed as "20:49 -0700" though it in fact is not from the
    * same day.
--- a/mailnews/mime/src/mimemoz2.cpp
+++ b/mailnews/mime/src/mimemoz2.cpp
@@ -588,17 +588,18 @@ MimeGetAttachmentList(MimeObject *tobj, 
   if (!mime_subclass_p(obj->clazz, (MimeObjectClass*) &mimeContainerClass))
     return ProcessBodyAsAttachment(obj, data);
 
   isAnInlineMessage = mime_typep(obj, (MimeObjectClass *) &mimeMessageClass);
 
   cobj = (MimeContainer*) obj;
   n = CountTotalMimeAttachments(cobj);
   if (n <= 0)
-    return n;
+    // XXX n is a regular number here, not meaningful as an nsresult
+    return static_cast<nsresult>(n);
 
   // in case of an inline message (as body), we need an extra slot for the
   // message itself that we will fill later...
   if (isAnInlineMessage)
     n ++;
 
   *data = new nsMsgAttachmentData[n + 1];
   if (!*data)
--- a/mailnews/mime/src/nsMimeHeaders.cpp
+++ b/mailnews/mime/src/nsMimeHeaders.cpp
@@ -23,17 +23,18 @@ NS_IMPL_ISUPPORTS1(nsMimeHeaders, nsIMim
 nsresult nsMimeHeaders::Initialize(const char *aAllHeaders, PRInt32 allHeadersSize)
 {
   /* just in case we want to reuse the object, cleanup...*/
   if (mHeaders)
     MimeHeaders_free(mHeaders);
 
   mHeaders = MimeHeaders_new();
   if (mHeaders)
-    return MimeHeaders_parse_line(aAllHeaders, allHeadersSize, mHeaders);
+    // XXX This function returns -1 in some paths, not nsresult
+    return static_cast<nsresult>(MimeHeaders_parse_line(aAllHeaders, allHeadersSize, mHeaders));
 
   return NS_ERROR_OUT_OF_MEMORY;
 }
 
 nsresult nsMimeHeaders::ExtractHeader(const char *headerName, bool getAllOfThem, char **_retval)
 {
   NS_ENSURE_ARG_POINTER(_retval);
   NS_ENSURE_TRUE(mHeaders, NS_ERROR_NOT_INITIALIZED);
--- a/mailnews/mime/src/nsStreamConverter.cpp
+++ b/mailnews/mime/src/nsStreamConverter.cpp
@@ -937,17 +937,19 @@ const char output[] = "\
     if (mEmitter)
     {
       rc = mEmitter->Write(Substring(buf, buf+readLen), &written);
     }
   }
   else if (mBridgeStream)
   {
     nsMIMESession   *tSession = (nsMIMESession *) mBridgeStream;
-    rc = tSession->put_block((nsMIMESession *)mBridgeStream, buf, readLen);
+    // XXX Casting int to nsresult
+    rc = static_cast<nsresult>(
+      tSession->put_block((nsMIMESession *)mBridgeStream, buf, readLen));
   }
 
   PR_FREEIF(buf);
   return rc;
 }
 
 /////////////////////////////////////////////////////////////////////////////
 // Methods for nsIRequestObserver
--- a/mailnews/news/src/nsNNTPNewsgroupList.cpp
+++ b/mailnews/news/src/nsNNTPNewsgroupList.cpp
@@ -449,17 +449,18 @@ nsNNTPNewsgroupList::AddToKnownArticles(
 
   if (!m_knownArts.set)
   {
     m_knownArts.set = nsMsgKeySet::Create();
     if (!m_knownArts.set)
       return NS_ERROR_OUT_OF_MEMORY;
   }
 
-  status = m_knownArts.set->AddRange(first, last);
+  // XXX Casting int to nsresult
+  status = static_cast<nsresult>(m_knownArts.set->AddRange(first, last));
 
   if (m_newsDB) {
     nsresult rv = NS_OK;
     nsCOMPtr <nsIDBFolderInfo> newsGroupInfo;
     rv = m_newsDB->GetDBFolderInfo(getter_AddRefs(newsGroupInfo));
     if (NS_SUCCEEDED(rv) && newsGroupInfo) {
       nsCString output;
       status = m_knownArts.set->Output(getter_Copies(output));