From 4ae87d0adc1e67856119de70b9e33a655ac68856 Mon Sep 17 00:00:00 2001 From: Wei-Cheng Pan Date: Mon, 8 Aug 2016 18:16:15 +0800 Subject: [PATCH] Bug 1293212 - Add MOZ_MUST_USE to prevent potential bugs. r=smaug MozReview-Commit-ID: EuyeBkDlk2G --HG-- extra : rebase_source : b728e1dd7e1ddfec3315f397e35dcb11eeab1ffa --- docshell/base/nsDocShell.cpp | 6 ++++-- uriloader/base/nsDocLoader.cpp | 10 ++++++---- uriloader/base/nsDocLoader.h | 14 +++++++------- uriloader/base/nsURILoader.h | 10 +++++----- uriloader/exthandler/ContentHandlerService.h | 2 +- uriloader/exthandler/ExternalHelperAppChild.h | 2 +- uriloader/exthandler/android/nsMIMEInfoAndroid.h | 10 +++++----- .../exthandler/android/nsOSHelperAppService.h | 2 +- uriloader/exthandler/gonk/nsOSHelperAppService.h | 2 +- uriloader/exthandler/mac/nsDecodeAppleFile.h | 2 +- uriloader/exthandler/mac/nsMIMEInfoMac.h | 8 ++++---- uriloader/exthandler/mac/nsOSHelperAppService.h | 6 +++--- uriloader/exthandler/mac/nsOSHelperAppService.mm | 3 ++- uriloader/exthandler/nsExternalHelperAppService.h | 2 +- 14 files changed, 42 insertions(+), 37 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 74f0910b4b2c..b06e287754a8 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -3316,7 +3316,8 @@ nsDocShell::SetDocLoaderParent(nsDocLoader* aParent) { bool wasFrame = IsFrame(); - nsDocLoader::SetDocLoaderParent(aParent); + nsresult rv = nsDocLoader::SetDocLoaderParent(aParent); + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr priorityGroup = do_QueryInterface(mLoadGroup); if (wasFrame != IsFrame() && priorityGroup) { @@ -4036,7 +4037,8 @@ nsDocShell::AddChild(nsIDocShellTreeItem* aChild) // Make sure to remove the child from its current parent. nsDocLoader* childsParent = childAsDocLoader->GetParent(); if (childsParent) { - childsParent->RemoveChildLoader(childAsDocLoader); + nsresult rv = childsParent->RemoveChildLoader(childAsDocLoader); + NS_ENSURE_SUCCESS(rv, rv); } // Make sure to clear the treeowner in case this child is a different type diff --git a/uriloader/base/nsDocLoader.cpp b/uriloader/base/nsDocLoader.cpp index 65834ace2d04..b9ac770233e9 100644 --- a/uriloader/base/nsDocLoader.cpp +++ b/uriloader/base/nsDocLoader.cpp @@ -345,7 +345,8 @@ nsDocLoader::Destroy() // Remove the document loader from the parent list of loaders... if (mParent) { - mParent->RemoveChildLoader(this); + nsresult rv = mParent->RemoveChildLoader(this); + NS_WARN_IF(NS_FAILED(rv)); } // Release all the information about network requests... @@ -376,7 +377,8 @@ nsDocLoader::DestroyChildren() if (loader) { // This is a safe cast, as we only put nsDocLoader objects into the // array - static_cast(loader)->SetDocLoaderParent(nullptr); + nsresult rv = static_cast(loader)->SetDocLoaderParent(nullptr); + NS_WARN_IF(NS_FAILED(rv)); } } mChildList.Clear(); @@ -616,7 +618,7 @@ nsresult nsDocLoader::RemoveChildLoader(nsDocLoader* aChild) { nsresult rv = mChildList.RemoveElement(aChild) ? NS_OK : NS_ERROR_FAILURE; if (NS_SUCCEEDED(rv)) { - aChild->SetDocLoaderParent(nullptr); + rv = aChild->SetDocLoaderParent(nullptr); } return rv; } @@ -625,7 +627,7 @@ nsresult nsDocLoader::AddChildLoader(nsDocLoader* aChild) { nsresult rv = mChildList.AppendElement(aChild) ? NS_OK : NS_ERROR_OUT_OF_MEMORY; if (NS_SUCCEEDED(rv)) { - aChild->SetDocLoaderParent(this); + rv = aChild->SetDocLoaderParent(this); } return rv; } diff --git a/uriloader/base/nsDocLoader.h b/uriloader/base/nsDocLoader.h index 466e13e698f3..481b1397bc70 100644 --- a/uriloader/base/nsDocLoader.h +++ b/uriloader/base/nsDocLoader.h @@ -58,7 +58,7 @@ public: nsDocLoader(); - virtual nsresult Init(); + virtual MOZ_MUST_USE nsresult Init(); static already_AddRefed GetAsDocLoader(nsISupports* aSupports); // Needed to deal with ambiguous inheritance from nsISupports... @@ -67,7 +67,7 @@ public: } // Add aDocLoader as a child to the docloader service. - static nsresult AddDocLoaderAsChildOfRoot(nsDocLoader* aDocLoader); + static MOZ_MUST_USE nsresult AddDocLoaderAsChildOfRoot(nsDocLoader* aDocLoader); NS_DECL_ISUPPORTS NS_DECL_NSIDOCUMENTLOADER @@ -89,10 +89,10 @@ public: // Remove aChild from our childlist. This nulls out the child's mParent // pointer. - nsresult RemoveChildLoader(nsDocLoader *aChild); + MOZ_MUST_USE nsresult RemoveChildLoader(nsDocLoader *aChild); // Add aChild to our child list. This will set aChild's mParent pointer to // |this|. - nsresult AddChildLoader(nsDocLoader* aChild); + MOZ_MUST_USE nsresult AddChildLoader(nsDocLoader* aChild); nsDocLoader* GetParent() const { return mParent; } struct nsListenerInfo { @@ -112,7 +112,7 @@ public: protected: virtual ~nsDocLoader(); - virtual nsresult SetDocLoaderParent(nsDocLoader * aLoader); + virtual MOZ_MUST_USE nsresult SetDocLoaderParent(nsDocLoader * aLoader); bool IsBusy(); @@ -164,7 +164,7 @@ protected: nsIURI *aUri, uint32_t aFlags); - bool RefreshAttempted(nsIWebProgress* aWebProgress, + MOZ_MUST_USE bool RefreshAttempted(nsIWebProgress* aWebProgress, nsIURI *aURI, int32_t aDelay, bool aSameURI); @@ -187,7 +187,7 @@ protected: // Inform a parent docloader that aChild is about to call its onload // handler. - bool ChildEnteringOnload(nsIDocumentLoader* aChild) { + MOZ_MUST_USE bool ChildEnteringOnload(nsIDocumentLoader* aChild) { // It's ok if we're already in the list -- we'll just be in there twice // and then the RemoveObject calls from ChildDoneWithOnload will remove // us. diff --git a/uriloader/base/nsURILoader.h b/uriloader/base/nsURILoader.h index 1921d2e881c8..2c5648dbae4d 100644 --- a/uriloader/base/nsURILoader.h +++ b/uriloader/base/nsURILoader.h @@ -35,11 +35,11 @@ protected: * Equivalent to nsIURILoader::openChannel, but allows specifying whether the * channel is opened already. */ - nsresult OpenChannel(nsIChannel* channel, - uint32_t aFlags, - nsIInterfaceRequestor* aWindowContext, - bool aChannelOpen, - nsIStreamListener** aListener); + MOZ_MUST_USE nsresult OpenChannel(nsIChannel* channel, + uint32_t aFlags, + nsIInterfaceRequestor* aWindowContext, + bool aChannelOpen, + nsIStreamListener** aListener); /** * we shouldn't need to have an owning ref count on registered diff --git a/uriloader/exthandler/ContentHandlerService.h b/uriloader/exthandler/ContentHandlerService.h index c8955ebcd97b..e39e89bc9005 100644 --- a/uriloader/exthandler/ContentHandlerService.h +++ b/uriloader/exthandler/ContentHandlerService.h @@ -21,7 +21,7 @@ public: NS_DECL_NSIHANDLERSERVICE ContentHandlerService(); - nsresult Init(); + MOZ_MUST_USE nsresult Init(); static void nsIHandlerInfoToHandlerInfo(nsIHandlerInfo* aInfo, HandlerInfo* aHandlerInfo); private: diff --git a/uriloader/exthandler/ExternalHelperAppChild.h b/uriloader/exthandler/ExternalHelperAppChild.h index 55ecf9324e5e..eecca01e6130 100644 --- a/uriloader/exthandler/ExternalHelperAppChild.h +++ b/uriloader/exthandler/ExternalHelperAppChild.h @@ -33,7 +33,7 @@ public: virtual bool RecvCancel(const nsresult& aStatus) override; private: virtual ~ExternalHelperAppChild(); - nsresult DivertToParent(nsIDivertableChannel *divertable, nsIRequest *request); + MOZ_MUST_USE nsresult DivertToParent(nsIDivertableChannel *divertable, nsIRequest *request); RefPtr mHandler; nsresult mStatus; diff --git a/uriloader/exthandler/android/nsMIMEInfoAndroid.h b/uriloader/exthandler/android/nsMIMEInfoAndroid.h index 2879ac85df1e..569d715bdf10 100644 --- a/uriloader/exthandler/android/nsMIMEInfoAndroid.h +++ b/uriloader/exthandler/android/nsMIMEInfoAndroid.h @@ -13,14 +13,14 @@ class nsMIMEInfoAndroid final : public nsIMIMEInfo { public: - static bool + static MOZ_MUST_USE bool GetMimeInfoForMimeType(const nsACString& aMimeType, nsMIMEInfoAndroid** aMimeInfo); - static bool + static MOZ_MUST_USE bool GetMimeInfoForFileExt(const nsACString& aFileExt, nsMIMEInfoAndroid** aMimeInfo); - static nsresult + static MOZ_MUST_USE nsresult GetMimeInfoForURL(const nsACString &aURL, bool *found, nsIHandlerInfo **info); @@ -33,8 +33,8 @@ public: private: ~nsMIMEInfoAndroid() {} - virtual nsresult LaunchDefaultWithFile(nsIFile* aFile); - virtual nsresult LoadUriInternal(nsIURI *aURI); + virtual MOZ_MUST_USE nsresult LaunchDefaultWithFile(nsIFile* aFile); + virtual MOZ_MUST_USE nsresult LoadUriInternal(nsIURI *aURI); nsCOMPtr mHandlerApps; nsCString mType; nsTArray mExtensions; diff --git a/uriloader/exthandler/android/nsOSHelperAppService.h b/uriloader/exthandler/android/nsOSHelperAppService.h index 2e1afbaae4f6..4f3623894f83 100644 --- a/uriloader/exthandler/android/nsOSHelperAppService.h +++ b/uriloader/exthandler/android/nsOSHelperAppService.h @@ -20,7 +20,7 @@ public: const nsACString& aFileExt, bool* aFound); - virtual nsresult + virtual MOZ_MUST_USE nsresult OSProtocolHandlerExists(const char* aScheme, bool* aExists); diff --git a/uriloader/exthandler/gonk/nsOSHelperAppService.h b/uriloader/exthandler/gonk/nsOSHelperAppService.h index 9d39876ec9d0..99a280bfcc97 100644 --- a/uriloader/exthandler/gonk/nsOSHelperAppService.h +++ b/uriloader/exthandler/gonk/nsOSHelperAppService.h @@ -31,7 +31,7 @@ public: const nsACString& aFileExt, bool* aFound); - virtual nsresult + virtual MOZ_MUST_USE nsresult OSProtocolHandlerExists(const char* aScheme, bool* aExists); }; diff --git a/uriloader/exthandler/mac/nsDecodeAppleFile.h b/uriloader/exthandler/mac/nsDecodeAppleFile.h index d59716d86132..cea2d701ec57 100644 --- a/uriloader/exthandler/mac/nsDecodeAppleFile.h +++ b/uriloader/exthandler/mac/nsDecodeAppleFile.h @@ -83,7 +83,7 @@ public: nsDecodeAppleFile(); virtual ~nsDecodeAppleFile(); - nsresult Initialize(nsIOutputStream *output, nsIFile *file); + MOZ_MUST_USE nsresult Initialize(nsIOutputStream *output, nsIFile *file); private: #define MAX_BUFFERSIZE 1024 diff --git a/uriloader/exthandler/mac/nsMIMEInfoMac.h b/uriloader/exthandler/mac/nsMIMEInfoMac.h index 247610e42e80..298357f757ca 100644 --- a/uriloader/exthandler/mac/nsMIMEInfoMac.h +++ b/uriloader/exthandler/mac/nsMIMEInfoMac.h @@ -16,15 +16,15 @@ class nsMIMEInfoMac : public nsMIMEInfoImpl { NS_IMETHOD LaunchWithFile(nsIFile* aFile); protected: - virtual nsresult LoadUriInternal(nsIURI *aURI); + virtual MOZ_MUST_USE nsresult LoadUriInternal(nsIURI *aURI); #ifdef DEBUG - virtual nsresult LaunchDefaultWithFile(nsIFile* aFile) { + virtual MOZ_MUST_USE nsresult LaunchDefaultWithFile(nsIFile* aFile) { NS_NOTREACHED("do not call this method, use LaunchWithFile"); return NS_ERROR_UNEXPECTED; } #endif - static nsresult OpenApplicationWithURI(nsIFile *aApplication, - const nsCString& aURI); + static MOZ_MUST_USE nsresult OpenApplicationWithURI(nsIFile *aApplication, + const nsCString& aURI); NS_IMETHOD GetDefaultDescription(nsAString& aDefaultDescription); diff --git a/uriloader/exthandler/mac/nsOSHelperAppService.h b/uriloader/exthandler/mac/nsOSHelperAppService.h index 5fb0a26c2c88..7371e1f42d51 100644 --- a/uriloader/exthandler/mac/nsOSHelperAppService.h +++ b/uriloader/exthandler/mac/nsOSHelperAppService.h @@ -36,10 +36,10 @@ public: // platformAppPath --> a platform specific path to an application that we got out of the // rdf data source. This can be a mac file spec, a unix path or a windows path depending on the platform // aFile --> an nsIFile representation of that platform application path. - virtual nsresult GetFileTokenForPath(const char16_t * platformAppPath, nsIFile ** aFile); + virtual MOZ_MUST_USE nsresult GetFileTokenForPath(const char16_t * platformAppPath, nsIFile ** aFile); - nsresult OSProtocolHandlerExists(const char * aScheme, - bool * aHandlerExists); + MOZ_MUST_USE nsresult OSProtocolHandlerExists(const char * aScheme, + bool * aHandlerExists); private: uint32_t mPermissions; diff --git a/uriloader/exthandler/mac/nsOSHelperAppService.mm b/uriloader/exthandler/mac/nsOSHelperAppService.mm index 0367e49bee4e..2c1f167ed7c6 100644 --- a/uriloader/exthandler/mac/nsOSHelperAppService.mm +++ b/uriloader/exthandler/mac/nsOSHelperAppService.mm @@ -560,7 +560,8 @@ nsOSHelperAppService::GetProtocolHandlerInfoFromOS(const nsACString &aScheme, } nsAutoString desc; - GetApplicationDescription(aScheme, desc); + rv = GetApplicationDescription(aScheme, desc); + NS_ENSURE_SUCCESS(rv, rv); handlerInfo->SetDefaultDescription(desc); return NS_OK; diff --git a/uriloader/exthandler/nsExternalHelperAppService.h b/uriloader/exthandler/nsExternalHelperAppService.h index aa16f0e17506..ca472ac71b14 100644 --- a/uriloader/exthandler/nsExternalHelperAppService.h +++ b/uriloader/exthandler/nsExternalHelperAppService.h @@ -67,7 +67,7 @@ public: * Initializes internal state. Will be called automatically when * this service is first instantiated. */ - nsresult Init(); + MOZ_MUST_USE nsresult Init(); /** * Given a mimetype and an extension, looks up a mime info from the OS.