Bug 717407 - Add null-arg checks and cleanup in mailnews/mime/src. r=neil
authoraceman <acelists@atlas.sk>
Wed, 07 Mar 2012 19:45:55 -0500
changeset 11026 1bb9b9a58eeae9ef2f94ed9796e643d95a6ff8d5
parent 11025 329a4f21d57431f1754bf7be032e7899007c4149
child 11027 0683a22dac2b2936542fa3fef62d3adbfcdbdf24
push id463
push userbugzilla@standard8.plus.com
push dateTue, 24 Apr 2012 17:34:51 +0000
treeherdercomm-beta@e53588e8f7b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersneil
bugs717407
Bug 717407 - Add null-arg checks and cleanup in mailnews/mime/src. r=neil
mailnews/mime/src/nsMimeConverter.cpp
mailnews/mime/src/nsMimeConverter.h
mailnews/mime/src/nsMimeHeaders.cpp
mailnews/mime/src/nsMimeObjectClassAccess.cpp
mailnews/mime/src/nsMimeObjectClassAccess.h
mailnews/mime/src/nsMsgHeaderParser.h
mailnews/mime/src/nsSimpleMimeConverterStub.cpp
mailnews/mime/src/nsStreamConverter.h
--- a/mailnews/mime/src/nsMimeConverter.cpp
+++ b/mailnews/mime/src/nsMimeConverter.cpp
@@ -69,124 +69,128 @@ nsMimeConverter::~nsMimeConverter()
 
 nsresult
 nsMimeConverter::DecodeMimeHeaderToCharPtr(const char *header,
                                            const char *default_charset,
                                            bool override_charset,
                                            bool eatContinuations,
                                            char **decodedString)
 {
-  *decodedString = MIME_DecodeMimeHeader(header, default_charset, 
-                                          override_charset,
-                                          eatContinuations);
+  NS_ENSURE_ARG_POINTER(decodedString);
+
+  *decodedString = MIME_DecodeMimeHeader(header, default_charset,
+                                         override_charset,
+                                         eatContinuations);
   return NS_OK;
 }
 
 // Decode routine (also converts output to unicode)
-nsresult 
+nsresult
 nsMimeConverter::DecodeMimeHeader(const char *header,
                                   const char *default_charset,
                                   bool override_charset,
                                   bool eatContinuations,
                                   nsAString& decodedString)
 {
   NS_ENSURE_ARG_POINTER(header);
 
-  char *decodedCstr = nsnull;
-
   // apply MIME decode.
-  decodedCstr = MIME_DecodeMimeHeader(header, default_charset,
-                                      override_charset, eatContinuations);
-  if (nsnull == decodedCstr) {
+  char *decodedCstr = MIME_DecodeMimeHeader(header, default_charset,
+                                            override_charset, eatContinuations);
+  if (!decodedCstr) {
     CopyUTF8toUTF16(nsDependentCString(header), decodedString);
   } else {
     CopyUTF8toUTF16(nsDependentCString(decodedCstr), decodedString);
     PR_FREEIF(decodedCstr);
   }
 
   return NS_OK;
 }
 
 nsresult
-nsMimeConverter::EncodeMimePartIIStr(const char    *header, 
-                                           bool          structured, 
-                                           const char    *mailCharset, 
-                                           PRInt32       fieldnamelen,
-                                           PRInt32 encodedWordSize, 
-                                           char          **encodedString)
+nsMimeConverter::EncodeMimePartIIStr(const char       *header,
+                                           bool       structured,
+                                           const char *mailCharset,
+                                           PRInt32    fieldnamelen,
+                                           PRInt32    encodedWordSize,
+                                           char       **encodedString)
 {
+  NS_ENSURE_ARG_POINTER(encodedString);
 
   // Encoder needs utf-8 string.
   nsAutoString tempUnicodeString;
   nsresult rv = ConvertToUnicode(mailCharset, header, tempUnicodeString);
   NS_ENSURE_SUCCESS(rv, rv);
-  rv = EncodeMimePartIIStr_UTF8(NS_ConvertUTF16toUTF8(tempUnicodeString), structured, mailCharset, fieldnamelen, encodedWordSize, encodedString);
-  return rv;
+  return EncodeMimePartIIStr_UTF8(NS_ConvertUTF16toUTF8(tempUnicodeString),
+                                  structured, mailCharset, fieldnamelen,
+                                  encodedWordSize, encodedString);
 }
 
 nsresult
 nsMimeConverter::EncodeMimePartIIStr_UTF8(const nsACString &header,
                                           bool             structured,
                                           const char       *mailCharset,
                                           PRInt32          fieldnamelen,
                                           PRInt32          encodedWordSize,
                                           char             **encodedString)
 {
+  NS_ENSURE_ARG_POINTER(encodedString);
+
   char *retString = MIME_EncodeMimePartIIStr(PromiseFlatCString(header).get(),
                                              structured, mailCharset,
                                              fieldnamelen, encodedWordSize);
-  if (retString == NULL)
-    return NS_ERROR_FAILURE;
-  else
-  {
-    *encodedString = retString;
-    return NS_OK;
-  }
+  NS_ENSURE_TRUE(retString, NS_ERROR_FAILURE);
+
+  *encodedString = retString;
+  return NS_OK;
 }
 
 
-nsresult 
-nsMimeConverter::B64EncoderInit(nsresult (*output_fn) (const char *buf, PRInt32 size, void *closure), void *closure, 
-                   MimeEncoderData **returnEncoderData) 
+nsresult
+nsMimeConverter::B64EncoderInit(nsresult (*output_fn) (const char *buf,
+                                PRInt32 size, void *closure), void *closure,
+                                MimeEncoderData **returnEncoderData)
 {
-MimeEncoderData   *ptr;
+  NS_ENSURE_ARG_POINTER(returnEncoderData);
+
+  MimeEncoderData   *ptr;
 
   ptr = MimeB64EncoderInit(output_fn, closure);
-  if (ptr)
-  {
-    *returnEncoderData = ptr;
-    return NS_OK;
-  }
-  else
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(ptr, NS_ERROR_OUT_OF_MEMORY);
+
+  *returnEncoderData = ptr;
+  return NS_OK;
 }
 
 nsresult
-nsMimeConverter::QPEncoderInit (nsresult (*output_fn) (const char *buf, 
-                      PRInt32 size, void *closure), void *closure, MimeEncoderData ** returnEncoderData) 
+nsMimeConverter::QPEncoderInit(nsresult (*output_fn) (const char *buf,
+                               PRInt32 size, void *closure), void *closure,
+                               MimeEncoderData **returnEncoderData)
 {
-MimeEncoderData   *ptr;
+  NS_ENSURE_ARG_POINTER(returnEncoderData);
+
+  MimeEncoderData *ptr;
 
   ptr = MimeQPEncoderInit(output_fn, closure);
-  if (ptr)
-  {
-    *returnEncoderData = ptr;
-    return NS_OK;
-  }
-  else
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(ptr, NS_ERROR_OUT_OF_MEMORY);
+
+  *returnEncoderData = ptr;
+  return NS_OK;
 }
 
 nsresult
-nsMimeConverter::EncoderDestroy(MimeEncoderData *data, bool abort_p) 
+nsMimeConverter::EncoderDestroy(MimeEncoderData *data, bool abort_p)
 {
   MimeEncoderDestroy(data, abort_p);
   return NS_OK;
 }
 
 nsresult
-nsMimeConverter::EncoderWrite (MimeEncoderData *data, const char *buffer, PRInt32 size, PRInt32 *written) 
+nsMimeConverter::EncoderWrite(MimeEncoderData *data, const char *buffer,
+                              PRInt32 size, PRInt32 *written)
 {
-  PRInt32   writeCount;
+  NS_ENSURE_ARG_POINTER(written);
+
+  PRInt32 writeCount;
   writeCount = MimeEncoderWrite(data, buffer, size);
   *written = writeCount;
   return NS_OK;
 }
--- a/mailnews/mime/src/nsMimeConverter.h
+++ b/mailnews/mime/src/nsMimeConverter.h
@@ -54,18 +54,18 @@
 
 #include "nsISupports.h"
 #include "prtypes.h"
 #include "nsIMimeConverter.h"
 #include "nsICharsetConverterManager.h"
 #include "nsCOMPtr.h"
 
 class nsMimeConverter : public nsIMimeConverter {
-public: 
+public:
   nsMimeConverter();
   virtual ~nsMimeConverter();
-       
+
   /* this macro defines QueryInterface, AddRef and Release for this class */
-  NS_DECL_ISUPPORTS 
+  NS_DECL_ISUPPORTS
   NS_DECL_NSIMIMECONVERTER
-}; 
+};
 
 #endif /* nsMimeConverter_h_ */
--- a/mailnews/mime/src/nsMimeHeaders.cpp
+++ b/mailnews/mime/src/nsMimeHeaders.cpp
@@ -48,49 +48,45 @@ nsMimeHeaders::nsMimeHeaders() :
 nsMimeHeaders::~nsMimeHeaders()
 {
   if (mHeaders)
     MimeHeaders_free(mHeaders);
 }
 
 NS_IMPL_ISUPPORTS1(nsMimeHeaders, nsIMimeHeaders)
 
-nsresult nsMimeHeaders::Initialize(const char * aAllHeaders, PRInt32 allHeadersSize)
+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);
 
   return NS_ERROR_OUT_OF_MEMORY;
 }
 
 nsresult nsMimeHeaders::ExtractHeader(const char *headerName, bool getAllOfThem, char **_retval)
 {
-  if (! mHeaders)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_ARG_POINTER(_retval);
+  NS_ENSURE_TRUE(mHeaders, NS_ERROR_NOT_INITIALIZED);
 
   *_retval = MimeHeaders_get(mHeaders, headerName, false, getAllOfThem);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMimeHeaders::GetAllHeaders(char **_retval)
 {
-    if (!mHeaders)
-        return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_ARG_POINTER(_retval);
+  NS_ENSURE_TRUE(mHeaders, NS_ERROR_NOT_INITIALIZED);
+  NS_ENSURE_TRUE(mHeaders->all_headers, NS_ERROR_NULL_POINTER);
 
-    if (!mHeaders->all_headers)
-        return NS_ERROR_NULL_POINTER;
+  char *allHeaders = (char *) NS_Alloc(mHeaders->all_headers_fp + 1);
+  NS_ENSURE_TRUE(allHeaders, NS_ERROR_OUT_OF_MEMORY);
 
-    char *allHeaders = (char *) PR_MALLOC(mHeaders->all_headers_fp + 1);
-    NS_ASSERTION (allHeaders, "nsMimeHeaders - out of memory");
-    if (!allHeaders)
-        return NS_ERROR_OUT_OF_MEMORY;
+  memcpy(allHeaders, mHeaders->all_headers, mHeaders->all_headers_fp);
+  *(allHeaders + mHeaders->all_headers_fp) = 0;
+  *_retval = allHeaders;
 
-    memcpy(allHeaders, mHeaders->all_headers, mHeaders->all_headers_fp);
-    *(allHeaders + mHeaders->all_headers_fp) = 0;
-    *_retval = allHeaders;
-
-    return NS_OK;
+  return NS_OK;
 }
--- a/mailnews/mime/src/nsMimeObjectClassAccess.cpp
+++ b/mailnews/mime/src/nsMimeObjectClassAccess.cpp
@@ -34,19 +34,19 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 #include <stdio.h>
 #include "mimecom.h"
 #include "nscore.h"
 #include "nsMimeObjectClassAccess.h"
 
-/* 
- * The following macros actually implement addref, release and 
- * query interface for our component. 
+/*
+ * The following macros actually implement addref, release and
+ * query interface for our component.
  */
 NS_IMPL_ISUPPORTS1(nsMimeObjectClassAccess, nsIMimeObjectClassAccess)
 
 /*
  * nsMimeObjectClassAccess definitions....
  */
 
 /* 
@@ -56,71 +56,70 @@ nsMimeObjectClassAccess::nsMimeObjectCla
 {
 }
 
 nsMimeObjectClassAccess::~nsMimeObjectClassAccess()
 {
 }
 
 nsresult
-nsMimeObjectClassAccess::MimeObjectWrite(void *mimeObject, 
-                                char *data, 
-                                PRInt32 length, 
-                                bool user_visible_p)
+nsMimeObjectClassAccess::MimeObjectWrite(void *mimeObject,
+                                         char *data,
+                                         PRInt32 length,
+                                         bool user_visible_p)
 {
   int rc = XPCOM_MimeObject_write(mimeObject, data, length, user_visible_p);
-  if (rc < 0)
-    return NS_ERROR_FAILURE;
-  else
-    return NS_OK;
+  NS_ENSURE_FALSE(rc < 0, NS_ERROR_FAILURE);
+
+  return NS_OK;
 }
 
-nsresult 
+nsresult
 nsMimeObjectClassAccess::GetmimeInlineTextClass(void **ptr)
 {
   *ptr = XPCOM_GetmimeInlineTextClass();
   return NS_OK;
 }
 
-nsresult 
+nsresult
 nsMimeObjectClassAccess::GetmimeLeafClass(void **ptr)
 {
   *ptr = XPCOM_GetmimeLeafClass();
   return NS_OK;
 }
 
-nsresult 
+nsresult
 nsMimeObjectClassAccess::GetmimeObjectClass(void **ptr)
 {
   *ptr = XPCOM_GetmimeObjectClass();
   return NS_OK;
 }
 
-nsresult 
+nsresult
 nsMimeObjectClassAccess::GetmimeContainerClass(void **ptr)
 {
   *ptr = XPCOM_GetmimeContainerClass();
   return NS_OK;
 }
 
-nsresult 
+nsresult
 nsMimeObjectClassAccess::GetmimeMultipartClass(void **ptr)
 {
   *ptr = XPCOM_GetmimeMultipartClass();
   return NS_OK;
 }
 
-nsresult 
+nsresult
 nsMimeObjectClassAccess::GetmimeMultipartSignedClass(void **ptr)
 {
   *ptr = XPCOM_GetmimeMultipartSignedClass();
   return NS_OK;
 }
 
-nsresult 
+nsresult
 nsMimeObjectClassAccess::GetmimeEncryptedClass(void **ptr)
 {
   *ptr = XPCOM_GetmimeEncryptedClass();
   return NS_OK;
 }
 
 nsresult
 nsMimeObjectClassAccess::MimeCreate(char * content_type, void * hdrs, void * opts, void **ptr)
--- a/mailnews/mime/src/nsMimeObjectClassAccess.h
+++ b/mailnews/mime/src/nsMimeObjectClassAccess.h
@@ -29,53 +29,53 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
- 
+
 /*
- * This interface is implemented by libmime. This interface is used by 
- * a Content-Type handler "Plug In" (i.e. vCard) for accessing various 
- * internal information about the object class system of libmime. When 
+ * This interface is implemented by libmime. This interface is used by
+ * a Content-Type handler "Plug In" (i.e. vCard) for accessing various
+ * internal information about the object class system of libmime. When
  * libmime progresses to a C++ object class, this would probably change.
  */
 #ifndef nsMimeObjectClassAccess_h_
 #define nsMimeObjectClassAccess_h_
 
 #include "nsISupports.h"
 #include "prtypes.h"
 #include "nsIMimeObjectClassAccess.h"
 
 class nsMimeObjectClassAccess : public nsIMimeObjectClassAccess {
-public: 
+public:
   nsMimeObjectClassAccess();
   virtual ~nsMimeObjectClassAccess();
-       
+
   /* this macro defines QueryInterface, AddRef and Release for this class */
-  NS_DECL_ISUPPORTS 
+  NS_DECL_ISUPPORTS
 
-  // These methods are all implemented by libmime to be used by 
-  // content type handler plugins for processing stream data. 
+  // These methods are all implemented by libmime to be used by
+  // content type handler plugins for processing stream data.
 
   // This is the write call for outputting processed stream data.
-  NS_IMETHOD    MimeObjectWrite(void *mimeObject, 
-                                char *data, 
-                                PRInt32 length, 
+  NS_IMETHOD    MimeObjectWrite(void *mimeObject,
+                                char *data,
+                                PRInt32 length,
                                 bool user_visible_p);
 
   // The following group of calls expose the pointers for the object
   // system within libmime.
   NS_IMETHOD    GetmimeInlineTextClass(void **ptr);
   NS_IMETHOD    GetmimeLeafClass(void **ptr);
   NS_IMETHOD    GetmimeObjectClass(void **ptr);
   NS_IMETHOD    GetmimeContainerClass(void **ptr);
   NS_IMETHOD    GetmimeMultipartClass(void **ptr);
   NS_IMETHOD    GetmimeMultipartSignedClass(void **ptr);
   NS_IMETHOD    GetmimeEncryptedClass(void **ptr);
 
   NS_IMETHOD    MimeCreate(char *content_type, void * hdrs, void * opts, void**ptr);
-}; 
+};
 
 #endif /* nsMimeObjectClassAccess_h_ */
--- a/mailnews/mime/src/nsMsgHeaderParser.h
+++ b/mailnews/mime/src/nsMsgHeaderParser.h
@@ -31,38 +31,38 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 /********************************************************************************************************
- 
+
    Interface for parsing RFC-822 addresses.
- 
+
 *********************************************************************************************************/
 
 #ifndef nsMSGRFCPARSER_h__
 #define nsMSGRFCPARSER_h__
 
 #include "msgCore.h"
 #include "nsIMsgHeaderParser.h" /* include the interface we are going to support */
 #include "nsIMimeConverter.h"
 #include "comi18n.h"
 #include "nsCOMPtr.h"
 
- /* 
+ /*
   * RFC-822 parser
-  */ 
+  */
 
 class nsMsgHeaderParser: public nsIMsgHeaderParser 
 {
-public: 
+public:
   nsMsgHeaderParser();
   virtual ~nsMsgHeaderParser();
 
   /* this macro defines QueryInterface, AddRef and Release for this class */
   NS_DECL_ISUPPORTS
   NS_DECL_NSIMSGHEADERPARSER
-}; 
+};
 
 #endif /* nsMSGRFCPARSER_h__ */
--- a/mailnews/mime/src/nsSimpleMimeConverterStub.cpp
+++ b/mailnews/mime/src/nsSimpleMimeConverterStub.cpp
@@ -88,47 +88,47 @@ GatherLine(const char *line, PRInt32 len
 {
     MimeSimpleStub *ssobj = (MimeSimpleStub *)obj;
 
     if (!obj->output_p ||
         !obj->options ||
         !obj->options->output_fn) {
         return 0;
     }
-    
+
     if (!obj->options->write_html_p)
         return MimeObject_write(obj, line, length, true);
 
     ssobj->buffer->Append(line);
     return 0;
 }
 
 static int
 EndGather(MimeObject *obj, bool abort_p)
 {
     MimeSimpleStub *ssobj = (MimeSimpleStub *)obj;
 
     if (obj->closed_p)
         return 0;
-    
+
     int status = ((MimeObjectClass *)MIME_GetmimeInlineTextClass())->parse_eof(obj, abort_p);
     if (status < 0)
         return status;
 
     if (ssobj->buffer->IsEmpty())
         return 0;
-    
-     mime_stream_data  *msd = (mime_stream_data *) (obj->options->stream_closure);
-     nsIChannel *channel = msd->channel;  // note the lack of ref counting...
-     if (channel)
-     {
-       nsCOMPtr<nsIURI> uri;
-       channel->GetURI(getter_AddRefs(uri));
-       ssobj->innerScriptable->SetUri(uri);
-     }
+
+    mime_stream_data  *msd = (mime_stream_data *) (obj->options->stream_closure);
+    nsIChannel *channel = msd->channel;  // note the lack of ref counting...
+    if (channel)
+    {
+        nsCOMPtr<nsIURI> uri;
+        channel->GetURI(getter_AddRefs(uri));
+        ssobj->innerScriptable->SetUri(uri);
+    }
     nsCString asHTML;
     nsresult rv = ssobj->innerScriptable->ConvertToHTML(nsDependentCString(obj->content_type),
                                                         *ssobj->buffer,
                                                         asHTML);
     if (NS_FAILED(rv)) {
         NS_ASSERTION(NS_SUCCEEDED(rv), "converter failure");
         return -1;
     }
@@ -139,36 +139,37 @@ EndGather(MimeObject *obj, bool abort_p)
     if (status < 0)
         return status;
     return 0;
 }
 
 static int
 Initialize(MimeObject *obj)
 {
-  MimeSimpleStub *ssobj = (MimeSimpleStub *)obj;
+    MimeSimpleStub *ssobj = (MimeSimpleStub *)obj;
 
-  nsresult rv;
-  nsCOMPtr<nsICategoryManager> catman =
-    do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
-  if (NS_FAILED(rv))
-    return -1;
+    nsresult rv;
+    nsCOMPtr<nsICategoryManager> catman =
+        do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
+    if (NS_FAILED(rv))
+        return -1;
 
-  nsCString value;
-  rv = catman->GetCategoryEntry(NS_SIMPLEMIMECONVERTERS_CATEGORY,
-                                obj->content_type, getter_Copies(value));
-  if (NS_FAILED(rv) || value.IsEmpty())
-    return -1;
+    nsCString value;
+    rv = catman->GetCategoryEntry(NS_SIMPLEMIMECONVERTERS_CATEGORY,
+                                  obj->content_type, getter_Copies(value));
+    if (NS_FAILED(rv) || value.IsEmpty())
+        return -1;
 
-  ssobj->innerScriptable = do_CreateInstance(value.get(), &rv);
-  if (NS_FAILED(rv) || !ssobj->innerScriptable)
-    return -1;
-  ssobj->buffer = new nsCString();
-  ((MimeObjectClass *)XPCOM_GetmimeLeafClass())->initialize(obj);
-  return 0;
+    ssobj->innerScriptable = do_CreateInstance(value.get(), &rv);
+    if (NS_FAILED(rv) || !ssobj->innerScriptable)
+        return -1;
+    ssobj->buffer = new nsCString();
+    ((MimeObjectClass *)XPCOM_GetmimeLeafClass())->initialize(obj);
+
+    return 0;
 }
 
 static void
 Finalize(MimeObject *obj)
 {
     MimeSimpleStub *ssobj = (MimeSimpleStub *)obj;
     ssobj->innerScriptable = nsnull;
     delete ssobj->buffer;
@@ -208,26 +209,27 @@ private:
 
 NS_IMPL_ISUPPORTS1(nsSimpleMimeConverterStub, nsIMimeContentTypeHandler)
 
 NS_IMETHODIMP
 nsSimpleMimeConverterStub::CreateContentTypeHandlerClass(const char *contentType,
                                                      contentTypeHandlerInitStruct *initStruct,
                                                          MimeObjectClass **objClass)
 {
+    NS_ENSURE_ARG_POINTER(objClass);
+
     *objClass = (MimeObjectClass *)&mimeSimpleStubClass;
     (*objClass)->superclass = (MimeObjectClass *)XPCOM_GetmimeInlineTextClass();
-    if (!(*objClass)->superclass)
-        return NS_ERROR_UNEXPECTED;;
+    NS_ENSURE_TRUE((*objClass)->superclass, NS_ERROR_UNEXPECTED);
 
     initStruct->force_inline_display = true;
     return NS_OK;;
 }
 
 nsresult
 MIME_NewSimpleMimeConverterStub(const char *aContentType,
                                 nsIMimeContentTypeHandler **aResult)
 {
     nsRefPtr<nsSimpleMimeConverterStub> inst = new nsSimpleMimeConverterStub(aContentType);
-    if (!inst)
-        return NS_ERROR_OUT_OF_MEMORY;
+    NS_ENSURE_TRUE(inst, NS_ERROR_OUT_OF_MEMORY);
+
     return CallQueryInterface(inst.get(), aResult);
 }
--- a/mailnews/mime/src/nsStreamConverter.h
+++ b/mailnews/mime/src/nsStreamConverter.h
@@ -33,32 +33,32 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 #ifndef nsStreamConverter_h_
 #define nsStreamConverter_h_
 
-#include "nsIStreamConverter.h" 
+#include "nsIStreamConverter.h"
 #include "nsIMimeStreamConverter.h"
-#include "nsIMimeEmitter.h" 
+#include "nsIMimeEmitter.h"
 #include "nsIURI.h"
 #include "nsIAsyncInputStream.h"
 #include "nsIAsyncOutputStream.h"
 #include "nsIChannel.h"
 #include "nsStringGlue.h"
 #include "nsCOMPtr.h"
 
 class nsStreamConverter : public nsIStreamConverter, public nsIMimeStreamConverter {
 public:
   nsStreamConverter();
   virtual ~nsStreamConverter();
 
-  NS_DECL_ISUPPORTS 
+  NS_DECL_ISUPPORTS
 
   // nsIMimeStreamConverter support
   NS_DECL_NSIMIMESTREAMCONVERTER
   // nsIStreamConverter methods
   NS_DECL_NSISTREAMCONVERTER
   // nsIStreamListener methods
   NS_DECL_NSISTREAMLISTENER
 
@@ -91,29 +91,29 @@ private:
 
   void                          *mBridgeStream;   // internal libmime data stream
 
   // Type of output, entire message, header only, body only
   nsCString                     mOutputFormat;
   nsCString                     mRealContentType; // if we know the content type for real, this will be set (used by attachments)
 
   nsCString                     mOverrideFormat;  // this is a possible override for emitter creation
-  bool                          mWrapperOutput;   // Should we output the frame split message display 
+  bool                          mWrapperOutput;   // Should we output the frame split message display
 
   nsCOMPtr<nsIMimeStreamConverterListener>  mMimeStreamConverterListener;
   bool                          mForwardInline;
   bool                          mForwardInlineFilter;
   bool                          mOverrideComposeFormat;
   nsString                      mForwardToAddress;
   nsCOMPtr<nsIMsgIdentity>      mIdentity;
   nsCString                     mOriginalMsgURI;
   nsCOMPtr<nsIMsgDBHdr>         mOrigMsgHdr;
 
   nsCString                     mFromType;
   nsCString                     mToType;
-#ifdef DEBUG_mscott  
+#ifdef DEBUG_mscott
   PRTime mConvertContentTime;
 #endif
   nsIRequest *                  mPendingRequest;  // used when we need to delay to fire onStartRequest
   nsISupports *                 mPendingContext;  // used when we need to delay to fire onStartRequest
 };
 
 #endif /* nsStreamConverter_h_ */