From 9bfc4e98e317a59653c0e3b9c9fbe8808fcf0943 Mon Sep 17 00:00:00 2001 From: Benjamin Smedberg Date: Tue, 19 Nov 2013 16:27:37 -0500 Subject: [PATCH] Bug 672843 part C - convert most of XPCOM except for xpcom/tests, r=vdjeric --- xpcom/base/nsCycleCollector.cpp | 33 +++++--- xpcom/base/nsDebugImpl.cpp | 3 +- xpcom/base/nsErrorService.cpp | 3 +- xpcom/base/nsGZFileWriter.cpp | 25 ++++-- xpcom/base/nsIMemoryReporter.idl | 3 +- xpcom/base/nsMacUtilsImpl.cpp | 3 +- xpcom/base/nsMemoryImpl.cpp | 3 +- xpcom/base/nsMemoryInfoDumper.cpp | 98 ++++++++++++++-------- xpcom/base/nsMemoryReporterManager.cpp | 18 ++-- xpcom/base/nsMessageLoop.cpp | 6 +- xpcom/base/nsSystemInfo.cpp | 12 ++- xpcom/build/Omnijar.cpp | 6 +- xpcom/build/nsXPCOMStrings.cpp | 6 +- xpcom/build/nsXPComInit.cpp | 56 +++++++------ xpcom/build/perfprobe.cpp | 3 +- xpcom/components/nsCategoryManager.cpp | 26 +++--- xpcom/components/nsComponentManager.cpp | 12 ++- xpcom/ds/nsHashPropertyBag.cpp | 3 +- xpcom/ds/nsINIParserImpl.cpp | 3 +- xpcom/ds/nsObserverService.cpp | 24 ++++-- xpcom/ds/nsProperties.cpp | 17 ++-- xpcom/ds/nsStringEnumerator.cpp | 31 +++---- xpcom/ds/nsSupportsArray.cpp | 3 +- xpcom/ds/nsSupportsPrimitives.cpp | 6 +- xpcom/ds/nsWindowsRegKey.cpp | 74 +++++++++++------ xpcom/glue/nsArrayEnumerator.cpp | 1 - xpcom/glue/nsCOMArray.cpp | 3 +- xpcom/glue/nsComponentManagerUtils.cpp | 18 ++-- xpcom/glue/nsINIParser.cpp | 3 +- xpcom/glue/nsMemory.cpp | 3 +- xpcom/glue/nsThreadUtils.cpp | 36 +++++--- xpcom/glue/nsThreadUtils.h | 3 +- xpcom/io/Base64.cpp | 3 +- xpcom/io/CocoaFileUtils.mm | 20 +++-- xpcom/io/nsAnonymousTemporaryFile.cpp | 36 +++++--- xpcom/io/nsAppFileLocationProvider.cpp | 19 +++-- xpcom/io/nsBinaryStream.cpp | 104 +++++++++++++++--------- xpcom/io/nsDirectoryService.cpp | 24 ++++-- xpcom/io/nsIOUtil.cpp | 8 +- xpcom/io/nsInputStreamTee.cpp | 16 ++-- xpcom/io/nsLocalFileCommon.cpp | 6 +- xpcom/io/nsLocalFileUnix.cpp | 93 ++++++++++++++------- xpcom/io/nsLocalFileWin.cpp | 72 ++++++++++------ xpcom/io/nsMultiplexInputStream.cpp | 58 ++++++++----- xpcom/io/nsPipe3.cpp | 3 +- xpcom/io/nsStorageStream.cpp | 31 +++---- xpcom/io/nsStringStream.cpp | 19 +++-- xpcom/reflect/xptcall/src/xptcall.cpp | 6 +- xpcom/threads/LazyIdleThread.cpp | 42 ++++++---- xpcom/threads/nsEnvironment.cpp | 12 ++- xpcom/threads/nsMemoryPressure.cpp | 1 - xpcom/threads/nsProcessCommon.cpp | 9 +- xpcom/threads/nsThread.cpp | 48 ++++++----- xpcom/threads/nsThreadManager.cpp | 15 ++-- xpcom/threads/nsThreadPool.cpp | 9 +- xpcom/threads/nsTimerImpl.cpp | 19 +++-- 56 files changed, 777 insertions(+), 440 deletions(-) diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp index 4079ca38ca5..a88436d36e8 100644 --- a/xpcom/base/nsCycleCollector.cpp +++ b/xpcom/base/nsCycleCollector.cpp @@ -1221,12 +1221,14 @@ public: // want scripts which poll the filesystem looking for gc/cc dumps to // grab a file before we're finished writing to it.) nsCOMPtr gcLogFile = CreateTempFile("incomplete-gc-edges"); - NS_ENSURE_STATE(gcLogFile); + if (NS_WARN_IF(!gcLogFile)) + return NS_ERROR_UNEXPECTED; // Dump the JS heap. FILE* gcLogANSIFile = nullptr; gcLogFile->OpenANSIFileDesc("w", &gcLogANSIFile); - NS_ENSURE_STATE(gcLogANSIFile); + if (NS_WARN_IF(!gcLogANSIFile)) + return NS_ERROR_UNEXPECTED; MozillaRegisterDebugFILE(gcLogANSIFile); CollectorData *data = sCollectorData.get(); if (data && data->mRuntime) @@ -1237,11 +1239,13 @@ public: // Strip off "incomplete-". nsCOMPtr gcLogFileFinalDestination = CreateTempFile("gc-edges"); - NS_ENSURE_STATE(gcLogFileFinalDestination); + if (NS_WARN_IF(!gcLogFileFinalDestination)) + return NS_ERROR_UNEXPECTED; nsAutoString gcLogFileFinalDestinationName; gcLogFileFinalDestination->GetLeafName(gcLogFileFinalDestinationName); - NS_ENSURE_STATE(!gcLogFileFinalDestinationName.IsEmpty()); + if (NS_WARN_IF(gcLogFileFinalDestinationName.IsEmpty())) + return NS_ERROR_UNEXPECTED; gcLogFile->MoveTo(/* directory */ nullptr, gcLogFileFinalDestinationName); @@ -1260,10 +1264,12 @@ public: // Open a file for dumping the CC graph. We again prefix with // "incomplete-". mOutFile = CreateTempFile("incomplete-cc-edges"); - NS_ENSURE_STATE(mOutFile); + if (NS_WARN_IF(!mOutFile)) + return NS_ERROR_UNEXPECTED; MOZ_ASSERT(!mStream); mOutFile->OpenANSIFileDesc("w", &mStream); - NS_ENSURE_STATE(mStream); + if (NS_WARN_IF(!mStream)) + return NS_ERROR_UNEXPECTED; MozillaRegisterDebugFILE(mStream); fprintf(mStream, "# WantAllTraces=%s\n", mWantAllTraces ? "true" : "false"); @@ -1388,11 +1394,13 @@ public: // Strip off "incomplete-" from the log file's name. nsCOMPtr logFileFinalDestination = CreateTempFile("cc-edges"); - NS_ENSURE_STATE(logFileFinalDestination); + if (NS_WARN_IF(!logFileFinalDestination)) + return NS_ERROR_UNEXPECTED; nsAutoString logFileFinalDestinationName; logFileFinalDestination->GetLeafName(logFileFinalDestinationName); - NS_ENSURE_STATE(!logFileFinalDestinationName.IsEmpty()); + if (NS_WARN_IF(logFileFinalDestinationName.IsEmpty())) + return NS_ERROR_UNEXPECTED; mOutFile->MoveTo(/* directory = */ nullptr, logFileFinalDestinationName); @@ -1415,7 +1423,8 @@ public: NS_IMETHOD ProcessNext(nsICycleCollectorHandler* aHandler, bool* aCanContinue) { - NS_ENSURE_STATE(aHandler && mWantAfterProcessing); + if (NS_WARN_IF(!aHandler) || NS_WARN_IF(!mWantAfterProcessing)) + return NS_ERROR_UNEXPECTED; CCGraphDescriber* d = mDescribers.popFirst(); if (d) { switch (d->mType) { @@ -1515,7 +1524,8 @@ nsCycleCollectorLoggerConstructor(nsISupports* aOuter, const nsIID& aIID, void* *aInstancePtr) { - NS_ENSURE_TRUE(!aOuter, NS_ERROR_NO_AGGREGATION); + if (NS_WARN_IF(aOuter)) + return NS_ERROR_NO_AGGREGATION; nsISupports *logger = new nsCycleCollectorLogger(); @@ -2438,7 +2448,8 @@ class CycleCollectorReporter MOZ_FINAL : public MemoryMultiReporter nsIMemoryReporter::KIND_HEAP, \ nsIMemoryReporter::UNITS_BYTES, _amount, \ NS_LITERAL_CSTRING(_desc), aClosure); \ - NS_ENSURE_SUCCESS(rv, rv); \ + if (NS_WARN_IF(NS_FAILED(rv))) \ + return rv; \ } \ } while (0) diff --git a/xpcom/base/nsDebugImpl.cpp b/xpcom/base/nsDebugImpl.cpp index cd9e12a1d0c..3cb01f4432a 100644 --- a/xpcom/base/nsDebugImpl.cpp +++ b/xpcom/base/nsDebugImpl.cpp @@ -565,7 +565,8 @@ static const nsDebugImpl kImpl; nsresult nsDebugImpl::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr) { - NS_ENSURE_NO_AGGREGATION(outer); + if (NS_WARN_IF(outer)) + return NS_ERROR_NO_AGGREGATION; return const_cast(&kImpl)-> QueryInterface(aIID, aInstancePtr); diff --git a/xpcom/base/nsErrorService.cpp b/xpcom/base/nsErrorService.cpp index dd5464d7e5c..58ef07b817f 100644 --- a/xpcom/base/nsErrorService.cpp +++ b/xpcom/base/nsErrorService.cpp @@ -65,7 +65,8 @@ NS_IMPL_ISUPPORTS1(nsErrorService, nsIErrorService) nsresult nsErrorService::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr) { - NS_ENSURE_NO_AGGREGATION(outer); + if (NS_WARN_IF(outer)) + return NS_ERROR_NO_AGGREGATION; nsRefPtr serv = new nsErrorService(); return serv->QueryInterface(aIID, aInstancePtr); } diff --git a/xpcom/base/nsGZFileWriter.cpp b/xpcom/base/nsGZFileWriter.cpp index c1e96cacf47..166e199d54c 100644 --- a/xpcom/base/nsGZFileWriter.cpp +++ b/xpcom/base/nsGZFileWriter.cpp @@ -33,21 +33,25 @@ nsGZFileWriter::~nsGZFileWriter() NS_IMETHODIMP nsGZFileWriter::Init(nsIFile* aFile) { - NS_ENSURE_FALSE(mInitialized, NS_ERROR_FAILURE); - NS_ENSURE_FALSE(mFinished, NS_ERROR_FAILURE); + if (NS_WARN_IF(mInitialized) || + NS_WARN_IF(mFinished)) + return NS_ERROR_FAILURE; // Get a FILE out of our nsIFile. Convert that into a file descriptor which // gzip can own. Then close our FILE, leaving only gzip's fd open. FILE* file; nsresult rv = aFile->OpenANSIFileDesc("wb", &file); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; mGZFile = gzdopen(dup(fileno(file)), "wb"); fclose(file); // gzdopen returns nullptr on error. - NS_ENSURE_TRUE(mGZFile, NS_ERROR_FAILURE); + if (NS_WARN_IF(!mGZFile)) + return NS_ERROR_FAILURE; + mInitialized = true; return NS_OK; @@ -56,8 +60,9 @@ nsGZFileWriter::Init(nsIFile* aFile) NS_IMETHODIMP nsGZFileWriter::Write(const nsACString& aStr) { - NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED); - NS_ENSURE_FALSE(mFinished, NS_ERROR_FAILURE); + if (NS_WARN_IF(!mInitialized) || + NS_WARN_IF(mFinished)) + return NS_ERROR_FAILURE; // gzwrite uses a return value of 0 to indicate failure. Otherwise, it // returns the number of uncompressed bytes written. To ensure we can @@ -71,7 +76,8 @@ nsGZFileWriter::Write(const nsACString& aStr) // always be either 0 or aStr.Length(), and we shouldn't have to call it // multiple times in order to get it to read the whole buffer. int rv = gzwrite(mGZFile, aStr.BeginReading(), aStr.Length()); - NS_ENSURE_TRUE(rv == static_cast(aStr.Length()), NS_ERROR_FAILURE); + if (NS_WARN_IF(rv != static_cast(aStr.Length()))) + return NS_ERROR_FAILURE; return NS_OK; } @@ -79,8 +85,9 @@ nsGZFileWriter::Write(const nsACString& aStr) NS_IMETHODIMP nsGZFileWriter::Finish() { - NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED); - NS_ENSURE_FALSE(mFinished, NS_ERROR_FAILURE); + if (NS_WARN_IF(!mInitialized) || + NS_WARN_IF(mFinished)) + return NS_ERROR_FAILURE; mFinished = true; gzclose(mGZFile); diff --git a/xpcom/base/nsIMemoryReporter.idl b/xpcom/base/nsIMemoryReporter.idl index 5a64aa83a91..df2154451e1 100644 --- a/xpcom/base/nsIMemoryReporter.idl +++ b/xpcom/base/nsIMemoryReporter.idl @@ -535,7 +535,8 @@ public: { int64_t amount; nsresult rv = GetAmount(&amount); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; return aCallback->Callback(EmptyCString(), mNameAndPath, mKind, mUnits, amount, mDescription, aData); diff --git a/xpcom/base/nsMacUtilsImpl.cpp b/xpcom/base/nsMacUtilsImpl.cpp index 84a030051dc..bf9828ad849 100644 --- a/xpcom/base/nsMacUtilsImpl.cpp +++ b/xpcom/base/nsMacUtilsImpl.cpp @@ -89,7 +89,8 @@ nsresult nsMacUtilsImpl::GetArchString(nsAString& archString) NS_IMETHODIMP nsMacUtilsImpl::GetIsUniversalBinary(bool *aIsUniversalBinary) { - NS_ENSURE_ARG_POINTER(aIsUniversalBinary); + if (NS_WARN_IF(!aIsUniversalBinary)) + return NS_ERROR_INVALID_ARG; *aIsUniversalBinary = false; nsAutoString archString; diff --git a/xpcom/base/nsMemoryImpl.cpp b/xpcom/base/nsMemoryImpl.cpp index f8b9bfc5a23..2b25086e13f 100644 --- a/xpcom/base/nsMemoryImpl.cpp +++ b/xpcom/base/nsMemoryImpl.cpp @@ -93,7 +93,8 @@ nsMemoryImpl::IsLowMemoryPlatform(bool *result) /*static*/ nsresult nsMemoryImpl::Create(nsISupports* outer, const nsIID& aIID, void **aResult) { - NS_ENSURE_NO_AGGREGATION(outer); + if (NS_WARN_IF(outer)) + return NS_ERROR_NO_AGGREGATION; return sGlobalMemory.QueryInterface(aIID, aResult); } diff --git a/xpcom/base/nsMemoryInfoDumper.cpp b/xpcom/base/nsMemoryInfoDumper.cpp index c5ae19f0840..23a4d5fcc5e 100644 --- a/xpcom/base/nsMemoryInfoDumper.cpp +++ b/xpcom/base/nsMemoryInfoDumper.cpp @@ -416,15 +416,18 @@ public: } } else { rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(file)); - NS_ENSURE_SUCCESS(rv, -1); + if (NS_WARN_IF(NS_FAILED(rv))) + return -1; } rv = file->AppendNative(NS_LITERAL_CSTRING("debug_info_trigger")); - NS_ENSURE_SUCCESS(rv, -1); + if (NS_WARN_IF(NS_FAILED(rv))) + return -1; nsAutoCString path; rv = file->GetNativePath(path); - NS_ENSURE_SUCCESS(rv, -1); + if (NS_WARN_IF(NS_FAILED(rv))) + return -1; // unlink might fail because the file doesn't exist, or for other reasons. // But we don't care it fails; any problems will be detected later, when we @@ -606,7 +609,8 @@ namespace mozilla { #define DUMP(o, s) \ do { \ nsresult rv = (o)->Write(s); \ - NS_ENSURE_SUCCESS(rv, rv); \ + if (NS_WARN_IF(NS_FAILED(rv))) \ + return rv; \ } while (0) static nsresult @@ -680,7 +684,8 @@ public: nsISupports *aData) { nsCOMPtr writer = do_QueryInterface(aData); - NS_ENSURE_TRUE(writer, NS_ERROR_FAILURE); + if (NS_WARN_IF(!writer)) + return NS_ERROR_FAILURE; nsresult rv = DumpReport(writer, mIsFirst, aProcess, aPath, aKind, aUnits, aAmount, aDescription); @@ -722,7 +727,8 @@ nsMemoryInfoDumper::OpenTempFile(const nsACString &aFilename, nsIFile* *aFile) nsresult rv; if (!*aFile) { rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, aFile); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; } #ifdef ANDROID @@ -731,7 +737,8 @@ nsMemoryInfoDumper::OpenTempFile(const nsACString &aFilename, nsIFile* *aFile) // users to be able to remove these files, so we write them into a // subdirectory of the temp directory and chmod 777 that directory. rv = (*aFile)->AppendNative(NS_LITERAL_CSTRING("memory-reports")); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; // It's OK if this fails; that probably just means that the directory already // exists. @@ -739,7 +746,8 @@ nsMemoryInfoDumper::OpenTempFile(const nsACString &aFilename, nsIFile* *aFile) nsAutoCString dirPath; rv = (*aFile)->GetNativePath(dirPath); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; while (chmod(dirPath.get(), 0777) == -1 && errno == EINTR) {} #endif @@ -747,10 +755,12 @@ nsMemoryInfoDumper::OpenTempFile(const nsACString &aFilename, nsIFile* *aFile) nsCOMPtr file(*aFile); rv = file->AppendNative(aFilename); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; rv = file->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0666); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; #ifdef ANDROID // Make this file world-read/writable; the permissions passed to the @@ -758,7 +768,8 @@ nsMemoryInfoDumper::OpenTempFile(const nsACString &aFilename, nsIFile* *aFile) // umask. nsAutoCString path; rv = file->GetNativePath(path); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; while (chmod(path.get(), 0666) == -1 && errno == EINTR) {} #endif @@ -801,7 +812,8 @@ DumpHeader(nsIGZFileWriter* aWriter) nsCOMPtr mgr = do_GetService("@mozilla.org/memory-reporter-manager;1"); - NS_ENSURE_STATE(mgr); + if (NS_WARN_IF(!mgr)) + return NS_ERROR_UNEXPECTED; DUMP(aWriter, mgr->GetHasMozMallocUsableSize() ? "true" : "false"); DUMP(aWriter, ",\n"); @@ -872,11 +884,12 @@ DumpProcessMemoryInfoToTempDir(const nsAString& aIdentifier) rv = nsMemoryInfoDumper::OpenTempFile(NS_LITERAL_CSTRING("incomplete-") + mrFilename, getter_AddRefs(mrTmpFile)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) return rv; nsRefPtr mrWriter = new nsGZFileWriter(); rv = mrWriter->Init(mrTmpFile); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; // Dump the memory reports to the file. DumpProcessMemoryReportsToGZFileWriter(mrWriter); @@ -894,11 +907,13 @@ DumpProcessMemoryInfoToTempDir(const nsAString& aIdentifier) nsCOMPtr dmdFile; rv = nsMemoryInfoDumper::OpenTempFile(dmdFilename, getter_AddRefs(dmdFile)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; nsRefPtr dmdWriter = new nsGZFileWriter(); rv = dmdWriter->Init(dmdFile); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; // Dump DMD output to the file. @@ -907,7 +922,8 @@ DumpProcessMemoryInfoToTempDir(const nsAString& aIdentifier) dmd::Dump(w); rv = dmdWriter->Finish(); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; #endif // MOZ_DMD // The call to Finish() deallocates the memory allocated by mrWriter's first @@ -916,42 +932,51 @@ DumpProcessMemoryInfoToTempDir(const nsAString& aIdentifier) // them -- by "heap-allocated" if nothing else -- we want DMD to see it as // well. So we deliberately don't call Finish() until after DMD finishes. rv = mrWriter->Finish(); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; // Rename the memory reports file, now that we're done writing all the files. // Its final name is "memory-report<-identifier>-.json.gz". nsCOMPtr mrFinalFile; rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(mrFinalFile)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; #ifdef ANDROID rv = mrFinalFile->AppendNative(NS_LITERAL_CSTRING("memory-reports")); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; #endif rv = mrFinalFile->AppendNative(mrFilename); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; rv = mrFinalFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; nsAutoString mrActualFinalFilename; rv = mrFinalFile->GetLeafName(mrActualFinalFilename); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; rv = mrTmpFile->MoveTo(/* directory */ nullptr, mrActualFinalFilename); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; // Write a message to the console. nsCOMPtr cs = do_GetService(NS_CONSOLESERVICE_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; nsString path; mrTmpFile->GetPath(path); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; nsString msg = NS_LITERAL_STRING( "nsIMemoryInfoDumper dumped reports to "); @@ -988,7 +1013,8 @@ nsMemoryInfoDumper::DumpMemoryInfoToTempDir(const nsAString& aIdentifier, /* dumpChildProcesses = */ false); nsCOMPtr mgr = do_GetService("@mozilla.org/memory-reporter-manager;1"); - NS_ENSURE_TRUE(mgr, NS_ERROR_FAILURE); + if (NS_WARN_IF(!mgr)) + return NS_ERROR_FAILURE; nsCOMPtr runnable; mgr->MinimizeMemoryUsage(callback, getter_AddRefs(runnable)); return NS_OK; @@ -1043,28 +1069,34 @@ nsMemoryInfoDumper::DumpMemoryReportsToNamedFile( nsCOMPtr mrFile; nsresult rv = NS_NewLocalFile(aFilename, false, getter_AddRefs(mrFile)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; mrFile->InitWithPath(aFilename); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; bool exists; rv = mrFile->Exists(&exists); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; if (!exists) { rv = mrFile->Create(nsIFile::NORMAL_FILE_TYPE, 0644); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; } // Write the memory reports to the file. nsRefPtr mrWriter = new nsGZFileWriter(); rv = mrWriter->Init(mrFile); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; rv = DumpHeader(mrWriter); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; // Process reports and finish up. nsRefPtr dumpReport = new DumpReportCallback(); diff --git a/xpcom/base/nsMemoryReporterManager.cpp b/xpcom/base/nsMemoryReporterManager.cpp index 3b470b9ae16..aa6cc938b46 100644 --- a/xpcom/base/nsMemoryReporterManager.cpp +++ b/xpcom/base/nsMemoryReporterManager.cpp @@ -102,7 +102,8 @@ private: *aAmount = 0; FILE *f = fopen("/proc/self/smaps", "r"); - NS_ENSURE_STATE(f); + if (NS_WARN_IF(!f)) + return NS_ERROR_UNEXPECTED; int64_t total = 0; char line[256]; @@ -752,7 +753,8 @@ public: nsIMemoryReporter::KIND_HEAP, \ nsIMemoryReporter::UNITS_BYTES, _amount, \ NS_LITERAL_CSTRING(_desc), aData); \ - NS_ENSURE_SUCCESS(rv, rv); \ + if (NS_WARN_IF(NS_FAILED(rv))) \ + return rv; \ } while (0) REPORT("explicit/dmd/stack-traces/used", @@ -1284,7 +1286,8 @@ NS_IMPL_ISUPPORTS1(ExplicitCallback, nsIHandleReportCallback) NS_IMETHODIMP nsMemoryReporterManager::GetExplicit(int64_t* aAmount) { - NS_ENSURE_ARG_POINTER(aAmount); + if (NS_WARN_IF(!aAmount)) + return NS_ERROR_INVALID_ARG; *aAmount = 0; #ifndef HAVE_JEMALLOC_STATS return NS_ERROR_NOT_AVAILABLE; @@ -1550,7 +1553,8 @@ NS_IMETHODIMP nsMemoryReporterManager::MinimizeMemoryUsage(nsIRunnable* aCallback, nsICancelableRunnable** aResult) { - NS_ENSURE_ARG_POINTER(aResult); + if (NS_WARN_IF(!aResult)) + return NS_ERROR_INVALID_ARG; nsRefPtr runnable = new MinimizeMemoryUsageRunnable(aCallback); @@ -1573,7 +1577,8 @@ nsMemoryReporterManager::SizeOfTab(nsIDOMWindow* aTopWindow, { nsCOMPtr global = do_QueryInterface(aTopWindow); nsCOMPtr piWindow = do_QueryInterface(aTopWindow); - NS_ENSURE_TRUE(!!global && !!piWindow, NS_ERROR_FAILURE); + if (NS_WARN_IF(!global) || NS_WARN_IF(!piWindow)) + return NS_ERROR_FAILURE; TimeStamp t1 = TimeStamp::Now(); @@ -1583,7 +1588,8 @@ nsMemoryReporterManager::SizeOfTab(nsIDOMWindow* aTopWindow, nsresult rv = mSizeOfTabFns.mJS(global->GetGlobalJSObject(), &jsObjectsSize, &jsStringsSize, &jsPrivateSize, &jsOtherSize); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; TimeStamp t2 = TimeStamp::Now(); diff --git a/xpcom/base/nsMessageLoop.cpp b/xpcom/base/nsMessageLoop.cpp index 0f1bd536e4e..8ef4c17a39a 100644 --- a/xpcom/base/nsMessageLoop.cpp +++ b/xpcom/base/nsMessageLoop.cpp @@ -87,7 +87,8 @@ nsresult MessageLoopIdleTask::Init(uint32_t aEnsureRunsAfterMS) { mTimer = do_CreateInstance("@mozilla.org/timer;1"); - NS_ENSURE_STATE(mTimer); + if (NS_WARN_IF(!mTimer)) + return NS_ERROR_UNEXPECTED; nsRefPtr callback = new MessageLoopTimerCallback(this); @@ -153,7 +154,8 @@ nsMessageLoopConstructor(nsISupports* aOuter, const nsIID& aIID, void** aInstancePtr) { - NS_ENSURE_FALSE(aOuter, NS_ERROR_NO_AGGREGATION); + if (NS_WARN_IF(aOuter)) + return NS_ERROR_NO_AGGREGATION; nsISupports* messageLoop = new nsMessageLoop(); return messageLoop->QueryInterface(aIID, aInstancePtr); } diff --git a/xpcom/base/nsSystemInfo.cpp b/xpcom/base/nsSystemInfo.cpp index 9439092ee94..0c32ac7901a 100644 --- a/xpcom/base/nsSystemInfo.cpp +++ b/xpcom/base/nsSystemInfo.cpp @@ -165,7 +165,8 @@ nsSystemInfo::Init() if (PR_GetSystemInfo(items[i].cmd, buf, sizeof(buf)) == PR_SUCCESS) { rv = SetPropertyAsACString(NS_ConvertASCIItoUTF16(items[i].name), nsDependentCString(buf)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; } else { NS_WARNING("PR_GetSystemInfo failed"); @@ -182,7 +183,8 @@ nsSystemInfo::Init() for (uint32_t i = 0; i < ArrayLength(cpuPropItems); i++) { rv = SetPropertyAsBool(NS_ConvertASCIItoUTF16(cpuPropItems[i].name), cpuPropItems[i].propfun()); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; } #ifdef XP_WIN @@ -191,7 +193,8 @@ nsSystemInfo::Init() NS_WARN_IF_FALSE(gotWow64Value, "IsWow64Process failed"); if (gotWow64Value) { rv = SetPropertyAsBool(NS_LITERAL_STRING("isWow64"), !!isWow64); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; } nsAutoCString hddModel, hddRevision; if (NS_SUCCEEDED(GetProfileHDDInfo(hddModel, hddRevision))) { @@ -210,7 +213,8 @@ nsSystemInfo::Init() rv = SetPropertyAsACString(NS_LITERAL_STRING("secondaryLibrary"), nsDependentCString(gtkver)); PR_smprintf_free(gtkver); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; } #endif diff --git a/xpcom/build/Omnijar.cpp b/xpcom/build/Omnijar.cpp index 4d75c7ef7b5..3bc74178821 100644 --- a/xpcom/build/Omnijar.cpp +++ b/xpcom/build/Omnijar.cpp @@ -145,7 +145,8 @@ Omnijar::GetURIString(Type aType, nsACString &result) nsAutoCString omniJarSpec; if (sPath[aType]) { nsresult rv = NS_GetURLSpecFromActualFile(sPath[aType], omniJarSpec); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; result = "jar:"; if (sIsNested[aType]) @@ -158,7 +159,8 @@ Omnijar::GetURIString(Type aType, nsACString &result) nsCOMPtr dir; nsDirectoryService::gService->Get(SPROP(aType), NS_GET_IID(nsIFile), getter_AddRefs(dir)); nsresult rv = NS_GetURLSpecFromActualFile(dir, result); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; } result += "/"; return NS_OK; diff --git a/xpcom/build/nsXPCOMStrings.cpp b/xpcom/build/nsXPCOMStrings.cpp index d5df93ac321..02796a835b1 100644 --- a/xpcom/build/nsXPCOMStrings.cpp +++ b/xpcom/build/nsXPCOMStrings.cpp @@ -40,7 +40,8 @@ NS_StringContainerInit2(nsStringContainer &aContainer, { if (aDataLength == UINT32_MAX) { - NS_ENSURE_ARG(!(aFlags & NS_STRING_CONTAINER_INIT_SUBSTRING)); + if (NS_WARN_IF(aFlags & NS_STRING_CONTAINER_INIT_SUBSTRING)) + return NS_ERROR_INVALID_ARG; aDataLength = nsCharTraits::length(aData); } @@ -200,7 +201,8 @@ NS_CStringContainerInit2(nsCStringContainer &aContainer, { if (aDataLength == UINT32_MAX) { - NS_ENSURE_ARG(!(aFlags & NS_CSTRING_CONTAINER_INIT_SUBSTRING)); + if (NS_WARN_IF(aFlags & NS_CSTRING_CONTAINER_INIT_SUBSTRING)) + return NS_ERROR_INVALID_ARG; aDataLength = nsCharTraits::length(aData); } diff --git a/xpcom/build/nsXPComInit.cpp b/xpcom/build/nsXPComInit.cpp index de58a8acd9e..c3784f3f972 100644 --- a/xpcom/build/nsXPComInit.cpp +++ b/xpcom/build/nsXPComInit.cpp @@ -219,7 +219,8 @@ nsThreadManagerGetSingleton(nsISupports* outer, void* *aInstancePtr) { NS_ASSERTION(aInstancePtr, "null outptr"); - NS_ENSURE_TRUE(!outer, NS_ERROR_NO_AGGREGATION); + if (NS_WARN_IF(outer)) + return NS_ERROR_NO_AGGREGATION; return nsThreadManager::get()->QueryInterface(aIID, aInstancePtr); } @@ -232,7 +233,8 @@ nsXPTIInterfaceInfoManagerGetSingleton(nsISupports* outer, void* *aInstancePtr) { NS_ASSERTION(aInstancePtr, "null outptr"); - NS_ENSURE_TRUE(!outer, NS_ERROR_NO_AGGREGATION); + if (NS_WARN_IF(outer)) + return NS_ERROR_NO_AGGREGATION; nsCOMPtr iim (XPTInterfaceInfoManager::GetSingleton()); @@ -313,16 +315,16 @@ static nsIDebug* gDebug = nullptr; EXPORT_XPCOM_API(nsresult) NS_GetDebug(nsIDebug** result) { - return nsDebugImpl::Create(nullptr, - NS_GET_IID(nsIDebug), + return nsDebugImpl::Create(nullptr, + NS_GET_IID(nsIDebug), (void**) result); } EXPORT_XPCOM_API(nsresult) NS_GetTraceRefcnt(nsITraceRefcnt** result) { - return nsTraceRefcntImpl::Create(nullptr, - NS_GET_IID(nsITraceRefcnt), + return nsTraceRefcntImpl::Create(nullptr, + NS_GET_IID(nsITraceRefcnt), (void**) result); } @@ -411,38 +413,38 @@ NS_InitXPCOM2(nsIServiceManager* *result, if (!AtExitManager::AlreadyRegistered()) { sExitManager = new AtExitManager(); - NS_ENSURE_STATE(sExitManager); } if (!MessageLoop::current()) { sMessageLoop = new MessageLoopForUI(MessageLoop::TYPE_MOZILLA_UI); - NS_ENSURE_STATE(sMessageLoop); } if (XRE_GetProcessType() == GeckoProcessType_Default && !BrowserProcessSubThread::GetMessageLoop(BrowserProcessSubThread::IO)) { scoped_ptr ioThread( new BrowserProcessSubThread(BrowserProcessSubThread::IO)); - NS_ENSURE_TRUE(ioThread.get(), NS_ERROR_OUT_OF_MEMORY); base::Thread::Options options; options.message_loop_type = MessageLoop::TYPE_IO; - NS_ENSURE_TRUE(ioThread->StartWithOptions(options), NS_ERROR_FAILURE); + if (NS_WARN_IF(!ioThread->StartWithOptions(options))) + return NS_ERROR_FAILURE; sIOThread = ioThread.release(); } // Establish the main thread here. rv = nsThreadManager::get()->Init(); - if (NS_FAILED(rv)) return rv; + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; // Set up the timer globals/timer thread rv = nsTimerImpl::Startup(); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; #ifndef ANDROID // If the locale hasn't already been setup by our embedder, - // get us out of the "C" locale and into the system + // get us out of the "C" locale and into the system if (strcmp(setlocale(LC_ALL, nullptr), "C") == 0) setlocale(LC_ALL, ""); #endif @@ -493,18 +495,21 @@ NS_InitXPCOM2(nsIServiceManager* *result, CommandLine::Init(0, nullptr); #else nsCOMPtr binaryFile; - nsDirectoryService::gService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, - NS_GET_IID(nsIFile), + nsDirectoryService::gService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, + NS_GET_IID(nsIFile), getter_AddRefs(binaryFile)); - NS_ENSURE_STATE(binaryFile); - + if (NS_WARN_IF(!binaryFile)) + return NS_ERROR_FAILURE; + rv = binaryFile->AppendNative(NS_LITERAL_CSTRING("nonexistent-executable")); - NS_ENSURE_SUCCESS(rv, rv); - + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; + nsCString binaryPath; rv = binaryFile->GetNativePath(binaryPath); - NS_ENSURE_SUCCESS(rv, rv); - + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; + static char const *const argv = { strdup(binaryPath.get()) }; CommandLine::Init(1, &argv); #endif @@ -568,7 +573,7 @@ NS_InitXPCOM2(nsIServiceManager* *result, mozilla::AvailableMemoryTracker::Activate(); // Notify observers of xpcom autoregistration start - NS_CreateServicesFromCategory(NS_XPCOM_STARTUP_CATEGORY, + NS_CreateServicesFromCategory(NS_XPCOM_STARTUP_CATEGORY, nullptr, NS_XPCOM_STARTUP_OBSERVER_ID); #ifdef XP_WIN @@ -626,7 +631,9 @@ ShutdownXPCOM(nsIServiceManager* servMgr) // Make sure the hang monitor is enabled for shutdown. HangMonitor::NotifyActivity(); - NS_ENSURE_STATE(NS_IsMainThread()); + if (!NS_IsMainThread()) { + NS_RUNTIMEABORT("Shutdown on wrong thread"); + } nsresult rv; nsCOMPtr moduleLoaders; @@ -637,7 +644,8 @@ ShutdownXPCOM(nsIServiceManager* servMgr) // servicemanager shutdown nsCOMPtr thread = do_GetCurrentThread(); - NS_ENSURE_STATE(thread); + if (NS_WARN_IF(!thread)) + return NS_ERROR_UNEXPECTED; nsRefPtr observerService; CallGetService("@mozilla.org/observer-service;1", diff --git a/xpcom/build/perfprobe.cpp b/xpcom/build/perfprobe.cpp index f74eb978e82..6c584b50c5a 100644 --- a/xpcom/build/perfprobe.cpp +++ b/xpcom/build/perfprobe.cpp @@ -213,7 +213,8 @@ nsresult ProbeManager::StartSession(nsTArray> &aProbes) used only for unregistration*/ ); delete[] probes; - NS_ENSURE_TRUE(result == ERROR_SUCCESS, NS_ERROR_UNEXPECTED); + if (NS_WARN_IF(result != ERROR_SUCCESS)) + return NS_ERROR_UNEXPECTED; return NS_OK; } diff --git a/xpcom/components/nsCategoryManager.cpp b/xpcom/components/nsCategoryManager.cpp index b35dc180665..6e2b43a635a 100644 --- a/xpcom/components/nsCategoryManager.cpp +++ b/xpcom/components/nsCategoryManager.cpp @@ -299,7 +299,8 @@ CategoryNode::DeleteLeaf(const char* aEntryName) NS_METHOD CategoryNode::Enumerate(nsISimpleEnumerator **_retval) { - NS_ENSURE_ARG_POINTER(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; MutexAutoLock lock(mLock); EntryEnumerator* enumObj = EntryEnumerator::Create(mTable); @@ -593,9 +594,10 @@ nsCategoryManager::GetCategoryEntry( const char *aCategoryName, const char *aEntryName, char **_retval ) { - NS_ENSURE_ARG_POINTER(aCategoryName); - NS_ENSURE_ARG_POINTER(aEntryName); - NS_ENSURE_ARG_POINTER(_retval); + if (NS_WARN_IF(!aCategoryName) || + NS_WARN_IF(!aEntryName) || + NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG;; nsresult status = NS_ERROR_NOT_AVAILABLE; @@ -687,8 +689,9 @@ nsCategoryManager::DeleteCategoryEntry( const char *aCategoryName, const char *aEntryName, bool aDontPersist) { - NS_ENSURE_ARG_POINTER(aCategoryName); - NS_ENSURE_ARG_POINTER(aEntryName); + if (NS_WARN_IF(!aCategoryName) || + NS_WARN_IF(!aEntryName)) + return NS_ERROR_INVALID_ARG; /* Note: no errors are reported since failure to delete @@ -715,7 +718,8 @@ nsCategoryManager::DeleteCategoryEntry( const char *aCategoryName, NS_IMETHODIMP nsCategoryManager::DeleteCategory( const char *aCategoryName ) { - NS_ENSURE_ARG_POINTER(aCategoryName); + if (NS_WARN_IF(!aCategoryName)) + return NS_ERROR_INVALID_ARG; // the categories are arena-allocated, so we don't // actually delete them. We just remove all of the @@ -740,8 +744,9 @@ NS_IMETHODIMP nsCategoryManager::EnumerateCategory( const char *aCategoryName, nsISimpleEnumerator **_retval ) { - NS_ENSURE_ARG_POINTER(aCategoryName); - NS_ENSURE_ARG_POINTER(_retval); + if (NS_WARN_IF(!aCategoryName) || + NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; CategoryNode* category; { @@ -759,7 +764,8 @@ nsCategoryManager::EnumerateCategory( const char *aCategoryName, NS_IMETHODIMP nsCategoryManager::EnumerateCategories(nsISimpleEnumerator **_retval) { - NS_ENSURE_ARG_POINTER(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; MutexAutoLock lock(mLock); CategoryEnumerator* enumObj = CategoryEnumerator::Create(mTable); diff --git a/xpcom/components/nsComponentManager.cpp b/xpcom/components/nsComponentManager.cpp index 0d27e9f17f8..af51024ac79 100644 --- a/xpcom/components/nsComponentManager.cpp +++ b/xpcom/components/nsComponentManager.cpp @@ -932,8 +932,9 @@ nsComponentManagerImpl::GetClassObjectByContractID(const char *contractID, const nsIID &aIID, void **aResult) { - NS_ENSURE_ARG_POINTER(aResult); - NS_ENSURE_ARG_POINTER(contractID); + if (NS_WARN_IF(!aResult) || + NS_WARN_IF(!contractID)) + return NS_ERROR_INVALID_ARG; nsresult rv; @@ -1052,7 +1053,8 @@ nsComponentManagerImpl::CreateInstanceByContractID(const char *aContractID, const nsIID &aIID, void **aResult) { - NS_ENSURE_ARG_POINTER(aContractID); + if (NS_WARN_IF(!aContractID)) + return NS_ERROR_INVALID_ARG; // test this first, since there's no point in creating a component during // shutdown -- whether it's available or not would depend on the order it @@ -1607,7 +1609,9 @@ NS_IMETHODIMP nsComponentManagerImpl::IsContractIDRegistered(const char *aClass, bool *_retval) { - NS_ENSURE_ARG_POINTER(aClass); + if (NS_WARN_IF(!aClass)) + return NS_ERROR_INVALID_ARG; + nsFactoryEntry *entry = GetFactoryEntry(aClass, strlen(aClass)); if (entry) diff --git a/xpcom/ds/nsHashPropertyBag.cpp b/xpcom/ds/nsHashPropertyBag.cpp index 29ea0c8c3eb..9f60de99aed 100644 --- a/xpcom/ds/nsHashPropertyBag.cpp +++ b/xpcom/ds/nsHashPropertyBag.cpp @@ -64,7 +64,8 @@ nsHashPropertyBag::GetProperty(const nsAString& name, nsIVariant* *_retval) NS_IMETHODIMP nsHashPropertyBag::SetProperty(const nsAString& name, nsIVariant *value) { - NS_ENSURE_ARG_POINTER(value); + if (NS_WARN_IF(!value)) + return NS_ERROR_INVALID_ARG; mPropertyHash.Put(name, value); diff --git a/xpcom/ds/nsINIParserImpl.cpp b/xpcom/ds/nsINIParserImpl.cpp index 1e442143637..86d6241356c 100644 --- a/xpcom/ds/nsINIParserImpl.cpp +++ b/xpcom/ds/nsINIParserImpl.cpp @@ -51,7 +51,8 @@ nsINIParserFactory::CreateInstance(nsISupports* aOuter, REFNSIID aIID, void **aResult) { - NS_ENSURE_NO_AGGREGATION(aOuter); + if (NS_WARN_IF(aOuter)) + return NS_ERROR_NO_AGGREGATION; // We are our own singleton. return QueryInterface(aIID, aResult); diff --git a/xpcom/ds/nsObserverService.cpp b/xpcom/ds/nsObserverService.cpp index b62b5d18853..f79fc75505b 100644 --- a/xpcom/ds/nsObserverService.cpp +++ b/xpcom/ds/nsObserverService.cpp @@ -150,7 +150,8 @@ ObserverServiceReporter::CollectReports(nsIMemoryReporterCallback* cb, "respect to the number of windows."), aClosure); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; } rv = cb->Callback(/* process */ EmptyCString(), @@ -162,7 +163,8 @@ ObserverServiceReporter::CollectReports(nsIMemoryReporterCallback* cb, "observer service."), aClosure); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; rv = cb->Callback(/* process */ EmptyCString(), NS_LITERAL_CSTRING("observer-service/referent/weak/alive"), @@ -173,7 +175,8 @@ ObserverServiceReporter::CollectReports(nsIMemoryReporterCallback* cb, "observer service that are still alive."), aClosure); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; rv = cb->Callback(/* process */ EmptyCString(), NS_LITERAL_CSTRING("observer-service/referent/weak/dead"), @@ -184,7 +187,8 @@ ObserverServiceReporter::CollectReports(nsIMemoryReporterCallback* cb, "observer service that are dead."), aClosure); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; return NS_OK; } @@ -266,7 +270,8 @@ nsObserverService::AddObserver(nsIObserver* anObserver, const char* aTopic, (void*) anObserver, aTopic)); NS_ENSURE_VALIDCALL - NS_ENSURE_ARG(anObserver && aTopic); + if (NS_WARN_IF(!anObserver) || NS_WARN_IF(!aTopic)) + return NS_ERROR_INVALID_ARG; if (mozilla::net::IsNeckoChild() && !strncmp(aTopic, "http-on-", 8)) { return NS_ERROR_NOT_IMPLEMENTED; @@ -285,7 +290,8 @@ nsObserverService::RemoveObserver(nsIObserver* anObserver, const char* aTopic) LOG(("nsObserverService::RemoveObserver(%p: %s)", (void*) anObserver, aTopic)); NS_ENSURE_VALIDCALL - NS_ENSURE_ARG(anObserver && aTopic); + if (NS_WARN_IF(!anObserver) || NS_WARN_IF(!aTopic)) + return NS_ERROR_INVALID_ARG; nsObserverList *observerList = mObserverTopicTable.GetEntry(aTopic); if (!observerList) @@ -302,7 +308,8 @@ nsObserverService::EnumerateObservers(const char* aTopic, nsISimpleEnumerator** anEnumerator) { NS_ENSURE_VALIDCALL - NS_ENSURE_ARG(aTopic && anEnumerator); + if (NS_WARN_IF(!anEnumerator) || NS_WARN_IF(!aTopic)) + return NS_ERROR_INVALID_ARG; nsObserverList *observerList = mObserverTopicTable.GetEntry(aTopic); if (!observerList) @@ -319,7 +326,8 @@ NS_IMETHODIMP nsObserverService::NotifyObservers(nsISupports *aSubject, LOG(("nsObserverService::NotifyObservers(%s)", aTopic)); NS_ENSURE_VALIDCALL - NS_ENSURE_ARG(aTopic); + if (NS_WARN_IF(!aTopic)) + return NS_ERROR_INVALID_ARG; nsObserverList *observerList = mObserverTopicTable.GetEntry(aTopic); if (observerList) diff --git a/xpcom/ds/nsProperties.cpp b/xpcom/ds/nsProperties.cpp index 27d1f28779e..8df2e9445c8 100644 --- a/xpcom/ds/nsProperties.cpp +++ b/xpcom/ds/nsProperties.cpp @@ -15,7 +15,8 @@ NS_INTERFACE_MAP_END NS_IMETHODIMP nsProperties::Get(const char* prop, const nsIID & uuid, void* *result) { - NS_ENSURE_ARG(prop); + if (NS_WARN_IF(!prop)) + return NS_ERROR_INVALID_ARG; nsCOMPtr value; if (!nsProperties_HashBase::Get(prop, getter_AddRefs(value))) { @@ -27,7 +28,8 @@ nsProperties::Get(const char* prop, const nsIID & uuid, void* *result) NS_IMETHODIMP nsProperties::Set(const char* prop, nsISupports* value) { - NS_ENSURE_ARG(prop); + if (NS_WARN_IF(!prop)) + return NS_ERROR_INVALID_ARG; Put(prop, value); return NS_OK; } @@ -35,7 +37,8 @@ nsProperties::Set(const char* prop, nsISupports* value) NS_IMETHODIMP nsProperties::Undefine(const char* prop) { - NS_ENSURE_ARG(prop); + if (NS_WARN_IF(!prop)) + return NS_ERROR_INVALID_ARG; nsCOMPtr value; if (!nsProperties_HashBase::Get(prop, getter_AddRefs(value))) @@ -48,7 +51,8 @@ nsProperties::Undefine(const char* prop) NS_IMETHODIMP nsProperties::Has(const char* prop, bool *result) { - NS_ENSURE_ARG(prop); + if (NS_WARN_IF(!prop)) + return NS_ERROR_INVALID_ARG; nsCOMPtr value; *result = nsProperties_HashBase::Get(prop, @@ -82,12 +86,11 @@ GetKeysEnumerate(const char *key, nsISupports* data, NS_IMETHODIMP nsProperties::GetKeys(uint32_t *count, char ***keys) { - NS_ENSURE_ARG(count); - NS_ENSURE_ARG(keys); + if (NS_WARN_IF(!count) || NS_WARN_IF(!keys)) + return NS_ERROR_INVALID_ARG; uint32_t n = Count(); char ** k = (char **) nsMemory::Alloc(n * sizeof(char *)); - NS_ENSURE_TRUE(k, NS_ERROR_OUT_OF_MEMORY); GetKeysEnumData gked; gked.keys = k; diff --git a/xpcom/ds/nsStringEnumerator.cpp b/xpcom/ds/nsStringEnumerator.cpp index c71bd5cebbe..8af28335460 100644 --- a/xpcom/ds/nsStringEnumerator.cpp +++ b/xpcom/ds/nsStringEnumerator.cpp @@ -84,7 +84,6 @@ NS_IMPL_ISUPPORTS3(nsStringEnumerator, NS_IMETHODIMP nsStringEnumerator::HasMore(bool* aResult) { - NS_ENSURE_ARG_POINTER(aResult); *aResult = mIndex < Count(); return NS_OK; } @@ -119,7 +118,8 @@ nsStringEnumerator::GetNext(nsISupports** aResult) NS_IMETHODIMP nsStringEnumerator::GetNext(nsAString& aResult) { - NS_ENSURE_TRUE(mIndex < Count(), NS_ERROR_UNEXPECTED); + if (NS_WARN_IF(mIndex >= Count())) + return NS_ERROR_UNEXPECTED; if (mIsUnicode) aResult = mArray->ElementAt(mIndex++); @@ -132,7 +132,8 @@ nsStringEnumerator::GetNext(nsAString& aResult) NS_IMETHODIMP nsStringEnumerator::GetNext(nsACString& aResult) { - NS_ENSURE_TRUE(mIndex < Count(), NS_ERROR_UNEXPECTED); + if (NS_WARN_IF(mIndex >= Count())) + return NS_ERROR_UNEXPECTED; if (mIsUnicode) CopyUTF16toUTF8(mArray->ElementAt(mIndex++), aResult); @@ -160,8 +161,8 @@ nsresult NS_NewStringEnumerator(nsIStringEnumerator** aResult, const nsTArray* aArray, nsISupports* aOwner) { - NS_ENSURE_ARG_POINTER(aResult); - NS_ENSURE_ARG_POINTER(aArray); + if (NS_WARN_IF(!aResult) || NS_WARN_IF(!aArray)) + return NS_ERROR_INVALID_ARG; *aResult = new nsStringEnumerator(aArray, aOwner); return StringEnumeratorTail(aResult); @@ -172,8 +173,8 @@ nsresult NS_NewUTF8StringEnumerator(nsIUTF8StringEnumerator** aResult, const nsTArray* aArray, nsISupports* aOwner) { - NS_ENSURE_ARG_POINTER(aResult); - NS_ENSURE_ARG_POINTER(aArray); + if (NS_WARN_IF(!aResult) || NS_WARN_IF(!aArray)) + return NS_ERROR_INVALID_ARG; *aResult = new nsStringEnumerator(aArray, aOwner); return StringEnumeratorTail(aResult); @@ -183,8 +184,8 @@ nsresult NS_NewAdoptingStringEnumerator(nsIStringEnumerator** aResult, nsTArray* aArray) { - NS_ENSURE_ARG_POINTER(aResult); - NS_ENSURE_ARG_POINTER(aArray); + if (NS_WARN_IF(!aResult) || NS_WARN_IF(!aArray)) + return NS_ERROR_INVALID_ARG; *aResult = new nsStringEnumerator(aArray, true); return StringEnumeratorTail(aResult); @@ -194,8 +195,8 @@ nsresult NS_NewAdoptingUTF8StringEnumerator(nsIUTF8StringEnumerator** aResult, nsTArray* aArray) { - NS_ENSURE_ARG_POINTER(aResult); - NS_ENSURE_ARG_POINTER(aArray); + if (NS_WARN_IF(!aResult) || NS_WARN_IF(!aArray)) + return NS_ERROR_INVALID_ARG; *aResult = new nsStringEnumerator(aArray, true); return StringEnumeratorTail(aResult); @@ -206,8 +207,8 @@ nsresult NS_NewStringEnumerator(nsIStringEnumerator** aResult, const nsTArray* aArray) { - NS_ENSURE_ARG_POINTER(aResult); - NS_ENSURE_ARG_POINTER(aArray); + if (NS_WARN_IF(!aResult) || NS_WARN_IF(!aArray)) + return NS_ERROR_INVALID_ARG; *aResult = new nsStringEnumerator(aArray, false); return StringEnumeratorTail(aResult); @@ -217,8 +218,8 @@ nsresult NS_NewUTF8StringEnumerator(nsIUTF8StringEnumerator** aResult, const nsTArray* aArray) { - NS_ENSURE_ARG_POINTER(aResult); - NS_ENSURE_ARG_POINTER(aArray); + if (NS_WARN_IF(!aResult) || NS_WARN_IF(!aArray)) + return NS_ERROR_INVALID_ARG; *aResult = new nsStringEnumerator(aArray, false); return StringEnumeratorTail(aResult); diff --git a/xpcom/ds/nsSupportsArray.cpp b/xpcom/ds/nsSupportsArray.cpp index 176c73cf28d..1c742f0eff6 100644 --- a/xpcom/ds/nsSupportsArray.cpp +++ b/xpcom/ds/nsSupportsArray.cpp @@ -585,7 +585,8 @@ nsSupportsArray::Clone(nsISupportsArray** aResult) { nsCOMPtr newArray; nsresult rv = NS_NewISupportsArray(getter_AddRefs(newArray)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; uint32_t count = 0; Count(&count); diff --git a/xpcom/ds/nsSupportsPrimitives.cpp b/xpcom/ds/nsSupportsPrimitives.cpp index a5c4f1d6146..fb6d61427fa 100644 --- a/xpcom/ds/nsSupportsPrimitives.cpp +++ b/xpcom/ds/nsSupportsPrimitives.cpp @@ -810,7 +810,8 @@ nsSupportsDependentCString::nsSupportsDependentCString(const char* aStr) NS_IMETHODIMP nsSupportsDependentCString::GetType(uint16_t *aType) { - NS_ENSURE_ARG_POINTER(aType); + if (NS_WARN_IF(!aType)) + return NS_ERROR_INVALID_ARG; *aType = TYPE_CSTRING; return NS_OK; @@ -826,7 +827,8 @@ nsSupportsDependentCString::GetData(nsACString& aData) NS_IMETHODIMP nsSupportsDependentCString::ToString(char **_retval) { - NS_ENSURE_ARG_POINTER(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; *_retval = ToNewCString(mData); if (!*_retval) diff --git a/xpcom/ds/nsWindowsRegKey.cpp b/xpcom/ds/nsWindowsRegKey.cpp index 524e382061b..25b51b4e79b 100644 --- a/xpcom/ds/nsWindowsRegKey.cpp +++ b/xpcom/ds/nsWindowsRegKey.cpp @@ -103,7 +103,8 @@ NS_IMETHODIMP nsWindowsRegKey::OpenChild(const nsAString &path, uint32_t mode, nsIWindowsRegKey **result) { - NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mKey)) + return NS_ERROR_NOT_INITIALIZED; nsCOMPtr child = new nsWindowsRegKey(); @@ -119,7 +120,8 @@ NS_IMETHODIMP nsWindowsRegKey::CreateChild(const nsAString &path, uint32_t mode, nsIWindowsRegKey **result) { - NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mKey)) + return NS_ERROR_NOT_INITIALIZED; nsCOMPtr child = new nsWindowsRegKey(); @@ -134,13 +136,15 @@ nsWindowsRegKey::CreateChild(const nsAString &path, uint32_t mode, NS_IMETHODIMP nsWindowsRegKey::GetChildCount(uint32_t *result) { - NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mKey)) + return NS_ERROR_NOT_INITIALIZED; DWORD numSubKeys; LONG rv = RegQueryInfoKeyW(mKey, nullptr, nullptr, nullptr, &numSubKeys, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); - NS_ENSURE_STATE(rv == ERROR_SUCCESS); + if (rv != ERROR_SUCCESS) + return NS_ERROR_FAILURE; *result = numSubKeys; return NS_OK; @@ -149,7 +153,8 @@ nsWindowsRegKey::GetChildCount(uint32_t *result) NS_IMETHODIMP nsWindowsRegKey::GetChildName(uint32_t index, nsAString &result) { - NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mKey)) + return NS_ERROR_NOT_INITIALIZED; FILETIME lastWritten; @@ -169,7 +174,8 @@ nsWindowsRegKey::GetChildName(uint32_t index, nsAString &result) NS_IMETHODIMP nsWindowsRegKey::HasChild(const nsAString &name, bool *result) { - NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mKey)) + return NS_ERROR_NOT_INITIALIZED; // Check for the existence of a child key by opening the key with minimal // rights. Perhaps there is a more efficient way to do this? @@ -187,13 +193,15 @@ nsWindowsRegKey::HasChild(const nsAString &name, bool *result) NS_IMETHODIMP nsWindowsRegKey::GetValueCount(uint32_t *result) { - NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mKey)) + return NS_ERROR_NOT_INITIALIZED; DWORD numValues; LONG rv = RegQueryInfoKeyW(mKey, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, &numValues, nullptr, nullptr, nullptr, nullptr); - NS_ENSURE_STATE(rv == ERROR_SUCCESS); + if (rv != ERROR_SUCCESS) + return NS_ERROR_FAILURE; *result = numValues; return NS_OK; @@ -202,7 +210,8 @@ nsWindowsRegKey::GetValueCount(uint32_t *result) NS_IMETHODIMP nsWindowsRegKey::GetValueName(uint32_t index, nsAString &result) { - NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mKey)) + return NS_ERROR_NOT_INITIALIZED; PRUnichar nameBuf[MAX_VALUE_NAME_LEN]; DWORD nameLen = sizeof(nameBuf) / sizeof(nameBuf[0]); @@ -220,7 +229,8 @@ nsWindowsRegKey::GetValueName(uint32_t index, nsAString &result) NS_IMETHODIMP nsWindowsRegKey::HasValue(const nsAString &name, bool *result) { - NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mKey)) + return NS_ERROR_NOT_INITIALIZED; LONG rv = RegQueryValueExW(mKey, PromiseFlatString(name).get(), 0, nullptr, nullptr, nullptr); @@ -232,7 +242,8 @@ nsWindowsRegKey::HasValue(const nsAString &name, bool *result) NS_IMETHODIMP nsWindowsRegKey::RemoveChild(const nsAString &name) { - NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mKey)) + return NS_ERROR_NOT_INITIALIZED; LONG rv = RegDeleteKeyW(mKey, PromiseFlatString(name).get()); @@ -242,7 +253,8 @@ nsWindowsRegKey::RemoveChild(const nsAString &name) NS_IMETHODIMP nsWindowsRegKey::RemoveValue(const nsAString &name) { - NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mKey)) + return NS_ERROR_NOT_INITIALIZED; LONG rv = RegDeleteValueW(mKey, PromiseFlatString(name).get()); @@ -252,7 +264,8 @@ nsWindowsRegKey::RemoveValue(const nsAString &name) NS_IMETHODIMP nsWindowsRegKey::GetValueType(const nsAString &name, uint32_t *result) { - NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mKey)) + return NS_ERROR_NOT_INITIALIZED; LONG rv = RegQueryValueExW(mKey, PromiseFlatString(name).get(), 0, (LPDWORD) result, nullptr, nullptr); @@ -263,7 +276,8 @@ nsWindowsRegKey::GetValueType(const nsAString &name, uint32_t *result) NS_IMETHODIMP nsWindowsRegKey::ReadStringValue(const nsAString &name, nsAString &result) { - NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mKey)) + return NS_ERROR_NOT_INITIALIZED; DWORD type, size; @@ -275,12 +289,12 @@ nsWindowsRegKey::ReadStringValue(const nsAString &name, nsAString &result) // This must be a string type in order to fetch the value as a string. // We're being a bit forgiving here by allowing types other than REG_SZ. - NS_ENSURE_STATE(type == REG_SZ || - type == REG_EXPAND_SZ || - type == REG_MULTI_SZ); + if (type != REG_SZ && type == REG_EXPAND_SZ && type == REG_MULTI_SZ) + return NS_ERROR_FAILURE; // The buffer size must be a multiple of 2. - NS_ENSURE_STATE(size % 2 == 0); + if (size % 2 != 0) + return NS_ERROR_UNEXPECTED; if (size == 0) { result.Truncate(); @@ -337,7 +351,8 @@ nsWindowsRegKey::ReadStringValue(const nsAString &name, nsAString &result) NS_IMETHODIMP nsWindowsRegKey::ReadIntValue(const nsAString &name, uint32_t *result) { - NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mKey)) + return NS_ERROR_NOT_INITIALIZED; DWORD size = sizeof(*result); LONG rv = RegQueryValueExW(mKey, PromiseFlatString(name).get(), 0, nullptr, @@ -349,7 +364,8 @@ nsWindowsRegKey::ReadIntValue(const nsAString &name, uint32_t *result) NS_IMETHODIMP nsWindowsRegKey::ReadInt64Value(const nsAString &name, uint64_t *result) { - NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mKey)) + return NS_ERROR_NOT_INITIALIZED; DWORD size = sizeof(*result); LONG rv = RegQueryValueExW(mKey, PromiseFlatString(name).get(), 0, nullptr, @@ -361,7 +377,8 @@ nsWindowsRegKey::ReadInt64Value(const nsAString &name, uint64_t *result) NS_IMETHODIMP nsWindowsRegKey::ReadBinaryValue(const nsAString &name, nsACString &result) { - NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mKey)) + return NS_ERROR_NOT_INITIALIZED; DWORD size; LONG rv = RegQueryValueExW(mKey, PromiseFlatString(name).get(), 0, @@ -385,7 +402,8 @@ nsWindowsRegKey::ReadBinaryValue(const nsAString &name, nsACString &result) NS_IMETHODIMP nsWindowsRegKey::WriteStringValue(const nsAString &name, const nsAString &value) { - NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mKey)) + return NS_ERROR_NOT_INITIALIZED; // Need to indicate complete size of buffer including null terminator. const nsString &flatValue = PromiseFlatString(value); @@ -400,7 +418,8 @@ nsWindowsRegKey::WriteStringValue(const nsAString &name, const nsAString &value) NS_IMETHODIMP nsWindowsRegKey::WriteIntValue(const nsAString &name, uint32_t value) { - NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mKey)) + return NS_ERROR_NOT_INITIALIZED; LONG rv = RegSetValueExW(mKey, PromiseFlatString(name).get(), 0, REG_DWORD, (const BYTE *) &value, sizeof(value)); @@ -411,7 +430,8 @@ nsWindowsRegKey::WriteIntValue(const nsAString &name, uint32_t value) NS_IMETHODIMP nsWindowsRegKey::WriteInt64Value(const nsAString &name, uint64_t value) { - NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mKey)) + return NS_ERROR_NOT_INITIALIZED; LONG rv = RegSetValueExW(mKey, PromiseFlatString(name).get(), 0, REG_QWORD, (const BYTE *) &value, sizeof(value)); @@ -422,7 +442,8 @@ nsWindowsRegKey::WriteInt64Value(const nsAString &name, uint64_t value) NS_IMETHODIMP nsWindowsRegKey::WriteBinaryValue(const nsAString &name, const nsACString &value) { - NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mKey)) + return NS_ERROR_NOT_INITIALIZED; const nsCString &flatValue = PromiseFlatCString(value); LONG rv = RegSetValueExW(mKey, PromiseFlatString(name).get(), 0, REG_BINARY, @@ -434,7 +455,8 @@ nsWindowsRegKey::WriteBinaryValue(const nsAString &name, const nsACString &value NS_IMETHODIMP nsWindowsRegKey::StartWatching(bool recurse) { - NS_ENSURE_TRUE(mKey, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mKey)) + return NS_ERROR_NOT_INITIALIZED; if (mWatchEvent) return NS_OK; diff --git a/xpcom/glue/nsArrayEnumerator.cpp b/xpcom/glue/nsArrayEnumerator.cpp index 572fc665a43..5c2588f5974 100644 --- a/xpcom/glue/nsArrayEnumerator.cpp +++ b/xpcom/glue/nsArrayEnumerator.cpp @@ -180,7 +180,6 @@ nsCOMArrayEnumerator::operator new (size_t size, const nsCOMArray_base& aArray) // do the actual allocation nsCOMArrayEnumerator * result = static_cast(::operator new(size)); - NS_ENSURE_TRUE(result, nullptr); // now need to copy over the values, and addref each one // now this might seem like a lot of work, but we're actually just diff --git a/xpcom/glue/nsCOMArray.cpp b/xpcom/glue/nsCOMArray.cpp index 99b1b5e481a..7b227a6c5a3 100644 --- a/xpcom/glue/nsCOMArray.cpp +++ b/xpcom/glue/nsCOMArray.cpp @@ -57,7 +57,8 @@ int32_t nsCOMArray_base::IndexOfObject(nsISupports* aObject) const { nsCOMPtr supports = do_QueryInterface(aObject); - NS_ENSURE_TRUE(supports, -1); + if (NS_WARN_IF(!supports)) + return -1; uint32_t i, count; int32_t retval = -1; diff --git a/xpcom/glue/nsComponentManagerUtils.cpp b/xpcom/glue/nsComponentManagerUtils.cpp index f20d5e72e3b..21decc4f4fa 100644 --- a/xpcom/glue/nsComponentManagerUtils.cpp +++ b/xpcom/glue/nsComponentManagerUtils.cpp @@ -46,7 +46,8 @@ nsresult CallGetService(const nsCID &aCID, const nsIID &aIID, void **aResult) { nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager; - NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!compMgr)) + return NS_ERROR_NOT_INITIALIZED; return compMgr->nsComponentManagerImpl::GetService(aCID, aIID, aResult); } @@ -55,7 +56,8 @@ nsresult CallGetService(const char *aContractID, const nsIID &aIID, void **aResult) { nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager; - NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!compMgr)) + return NS_ERROR_NOT_INITIALIZED; return compMgr-> nsComponentManagerImpl::GetServiceByContractID(aContractID, @@ -119,7 +121,8 @@ CallCreateInstance(const nsCID &aCID, nsISupports *aDelegate, const nsIID &aIID, void **aResult) { nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager; - NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!compMgr)) + return NS_ERROR_NOT_INITIALIZED; return compMgr-> nsComponentManagerImpl::CreateInstance(aCID, aDelegate, aIID, aResult); @@ -130,7 +133,8 @@ CallCreateInstance(const char *aContractID, nsISupports *aDelegate, const nsIID &aIID, void **aResult) { nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager; - NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!compMgr)) + return NS_ERROR_NOT_INITIALIZED; return compMgr-> nsComponentManagerImpl::CreateInstanceByContractID(aContractID, @@ -142,7 +146,8 @@ nsresult CallGetClassObject(const nsCID &aCID, const nsIID &aIID, void **aResult) { nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager; - NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!compMgr)) + return NS_ERROR_NOT_INITIALIZED; return compMgr-> nsComponentManagerImpl::GetClassObject(aCID, aIID, aResult); @@ -152,7 +157,8 @@ nsresult CallGetClassObject(const char *aContractID, const nsIID &aIID, void **aResult) { nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager; - NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!compMgr)) + return NS_ERROR_NOT_INITIALIZED; return compMgr-> nsComponentManagerImpl::GetClassObjectByContractID(aContractID, aIID, diff --git a/xpcom/glue/nsINIParser.cpp b/xpcom/glue/nsINIParser.cpp index 918c2f2427d..9ce71aa9b0f 100644 --- a/xpcom/glue/nsINIParser.cpp +++ b/xpcom/glue/nsINIParser.cpp @@ -65,7 +65,8 @@ nsINIParser::Init(nsIFile* aFile) #ifdef XP_WIN nsAutoString path; nsresult rv = aFile->GetPath(path); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; fd = _wfopen(path.get(), READ_BINARYMODE); #else diff --git a/xpcom/glue/nsMemory.cpp b/xpcom/glue/nsMemory.cpp index 6b63420c9ec..f77567a3f68 100644 --- a/xpcom/glue/nsMemory.cpp +++ b/xpcom/glue/nsMemory.cpp @@ -19,7 +19,8 @@ nsMemory::HeapMinimize(bool aImmediate) { nsCOMPtr mem; nsresult rv = NS_GetMemoryManager(getter_AddRefs(mem)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; return mem->HeapMinimize(aImmediate); } diff --git a/xpcom/glue/nsThreadUtils.cpp b/xpcom/glue/nsThreadUtils.cpp index a99c2dea3ca..c89faa4e774 100644 --- a/xpcom/glue/nsThreadUtils.cpp +++ b/xpcom/glue/nsThreadUtils.cpp @@ -70,15 +70,18 @@ NS_NewThread(nsIThread **result, nsIRunnable *event, uint32_t stackSize) nsresult rv; nsCOMPtr mgr = do_GetService(NS_THREADMANAGER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; rv = mgr->NewThread(0, stackSize, getter_AddRefs(thread)); #endif - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; if (event) { rv = thread->Dispatch(event, NS_DISPATCH_NORMAL); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; } *result = nullptr; @@ -95,7 +98,8 @@ NS_GetCurrentThread(nsIThread **result) nsresult rv; nsCOMPtr mgr = do_GetService(NS_THREADMANAGER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; return mgr->GetCurrentThread(result); #endif } @@ -109,7 +113,8 @@ NS_GetMainThread(nsIThread **result) nsresult rv; nsCOMPtr mgr = do_GetService(NS_THREADMANAGER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; return mgr->GetMainThread(result); #endif } @@ -161,7 +166,8 @@ NS_DispatchToCurrentThread(nsIRunnable *event) #else nsCOMPtr thread; nsresult rv = NS_GetCurrentThread(getter_AddRefs(thread)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; #endif return thread->Dispatch(event, NS_DISPATCH_NORMAL); } @@ -171,7 +177,8 @@ NS_DispatchToMainThread(nsIRunnable *event, uint32_t dispatchFlags) { nsCOMPtr thread; nsresult rv = NS_GetMainThread(getter_AddRefs(thread)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; return thread->Dispatch(event, dispatchFlags); } @@ -184,13 +191,15 @@ NS_ProcessPendingEvents(nsIThread *thread, PRIntervalTime timeout) #ifdef MOZILLA_INTERNAL_API if (!thread) { thread = NS_GetCurrentThread(); - NS_ENSURE_STATE(thread); + if (NS_WARN_IF(!thread)) + return NS_ERROR_UNEXPECTED; } #else nsCOMPtr current; if (!thread) { rv = NS_GetCurrentThread(getter_AddRefs(current)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; thread = current.get(); } #endif @@ -225,7 +234,8 @@ NS_HasPendingEvents(nsIThread *thread) return hasPendingEvents(current); #else thread = NS_GetCurrentThread(); - NS_ENSURE_TRUE(thread, false); + if (NS_WARN_IF(!thread)) + return false; #endif } return hasPendingEvents(thread); @@ -237,13 +247,15 @@ NS_ProcessNextEvent(nsIThread *thread, bool mayWait) #ifdef MOZILLA_INTERNAL_API if (!thread) { thread = NS_GetCurrentThread(); - NS_ENSURE_TRUE(thread, false); + if (NS_WARN_IF(!thread)) + return false; } #else nsCOMPtr current; if (!thread) { NS_GetCurrentThread(getter_AddRefs(current)); - NS_ENSURE_TRUE(current, false); + if (NS_WARN_IF(!current)) + return false; thread = current.get(); } #endif diff --git a/xpcom/glue/nsThreadUtils.h b/xpcom/glue/nsThreadUtils.h index e53cc013153..c567de3a466 100644 --- a/xpcom/glue/nsThreadUtils.h +++ b/xpcom/glue/nsThreadUtils.h @@ -71,7 +71,8 @@ NS_NewNamedThread(const char (&name)[LEN], uint32_t stackSize = nsIThreadManager::DEFAULT_STACK_SIZE) { nsresult rv = NS_NewThread(result, nullptr, stackSize); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; NS_SetThreadName(*result, name); if (initialEvent) { rv = (*result)->Dispatch(initialEvent, NS_DISPATCH_NORMAL); diff --git a/xpcom/io/Base64.cpp b/xpcom/io/Base64.cpp index 94fec02775a..4a6419eca57 100644 --- a/xpcom/io/Base64.cpp +++ b/xpcom/io/Base64.cpp @@ -163,7 +163,8 @@ EncodeInputStream(nsIInputStream *aInputStream, if (!aCount) { rv = aInputStream->Available(&count64); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; // if count64 is over 4GB, it will be failed at the below condition, // then will return NS_ERROR_OUT_OF_MEMORY aCount = (uint32_t)count64; diff --git a/xpcom/io/CocoaFileUtils.mm b/xpcom/io/CocoaFileUtils.mm index ca4e1b4fc3b..3f687274553 100644 --- a/xpcom/io/CocoaFileUtils.mm +++ b/xpcom/io/CocoaFileUtils.mm @@ -16,7 +16,8 @@ nsresult RevealFileInFinder(CFURLRef url) { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; - NS_ENSURE_ARG_POINTER(url); + if (NS_WARN_IF(!url)) + return NS_ERROR_INVALID_ARG; NSAutoreleasePool* ap = [[NSAutoreleasePool alloc] init]; BOOL success = [[NSWorkspace sharedWorkspace] selectFile:[(NSURL*)url path] inFileViewerRootedAtPath:@""]; @@ -31,7 +32,8 @@ nsresult OpenURL(CFURLRef url) { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; - NS_ENSURE_ARG_POINTER(url); + if (NS_WARN_IF(!url)) + return NS_ERROR_INVALID_ARG; NSAutoreleasePool* ap = [[NSAutoreleasePool alloc] init]; BOOL success = [[NSWorkspace sharedWorkspace] openURL:(NSURL*)url]; @@ -46,8 +48,8 @@ nsresult GetFileCreatorCode(CFURLRef url, OSType *creatorCode) { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; - NS_ENSURE_ARG_POINTER(url); - NS_ENSURE_ARG_POINTER(creatorCode); + if (NS_WARN_IF(!url) || NS_WARN_IF(!creatorCode)) + return NS_ERROR_INVALID_ARG; nsAutoreleasePool localPool; @@ -76,7 +78,8 @@ nsresult SetFileCreatorCode(CFURLRef url, OSType creatorCode) { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; - NS_ENSURE_ARG_POINTER(url); + if (NS_WARN_IF(!url)) + return NS_ERROR_INVALID_ARG; NSAutoreleasePool* ap = [[NSAutoreleasePool alloc] init]; NSDictionary* dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithUnsignedLong:creatorCode] forKey:NSFileHFSCreatorCode]; @@ -91,8 +94,8 @@ nsresult GetFileTypeCode(CFURLRef url, OSType *typeCode) { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; - NS_ENSURE_ARG_POINTER(url); - NS_ENSURE_ARG_POINTER(typeCode); + if (NS_WARN_IF(!url) || NS_WARN_IF(!typeCode)) + return NS_ERROR_INVALID_ARG; nsAutoreleasePool localPool; @@ -121,7 +124,8 @@ nsresult SetFileTypeCode(CFURLRef url, OSType typeCode) { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; - NS_ENSURE_ARG_POINTER(url); + if (NS_WARN_IF(!url)) + return NS_ERROR_INVALID_ARG; NSAutoreleasePool* ap = [[NSAutoreleasePool alloc] init]; NSDictionary* dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithUnsignedLong:typeCode] forKey:NSFileHFSTypeCode]; diff --git a/xpcom/io/nsAnonymousTemporaryFile.cpp b/xpcom/io/nsAnonymousTemporaryFile.cpp index aaac18958a2..de0cc43caf2 100644 --- a/xpcom/io/nsAnonymousTemporaryFile.cpp +++ b/xpcom/io/nsAnonymousTemporaryFile.cpp @@ -50,19 +50,23 @@ using namespace mozilla; static nsresult GetTempDir(nsIFile** aTempDir) { - NS_ENSURE_ARG(aTempDir); + if (NS_WARN_IF(!aTempDir)) + return NS_ERROR_INVALID_ARG; nsCOMPtr tmpFile; nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tmpFile)); - NS_ENSURE_SUCCESS(rv,rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; #ifdef XP_WIN // On windows DELETE_ON_CLOSE is unreliable, so we store temporary files // in a subdir of the temp dir and delete that in an idle service observer // to ensure it's been cleared. rv = tmpFile->AppendNative(nsDependentCString("mozilla-temp-files")); - NS_ENSURE_SUCCESS(rv,rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; rv = tmpFile->Create(nsIFile::DIRECTORY_TYPE, 0700); - NS_ENSURE_TRUE(rv == NS_ERROR_FILE_ALREADY_EXISTS || NS_SUCCEEDED(rv), rv); + if (rv != NS_ERROR_FILE_ALREADY_EXISTS && NS_WARN_IF(NS_FAILED(rv))) + return rv; #endif tmpFile.forget(aTempDir); @@ -73,12 +77,14 @@ GetTempDir(nsIFile** aTempDir) nsresult NS_OpenAnonymousTemporaryFile(PRFileDesc** aOutFileDesc) { - NS_ENSURE_ARG(aOutFileDesc); + if (NS_WARN_IF(!aOutFileDesc)) + return NS_ERROR_INVALID_ARG; nsresult rv; nsCOMPtr tmpFile; rv = GetTempDir(getter_AddRefs(tmpFile)); - NS_ENSURE_SUCCESS(rv,rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; // Give the temp file a name with a random element. CreateUnique will also // append a counter to the name if it encounters a name collision. Adding @@ -90,10 +96,12 @@ NS_OpenAnonymousTemporaryFile(PRFileDesc** aOutFileDesc) name.AppendInt(rand()); rv = tmpFile->AppendNative(name); - NS_ENSURE_SUCCESS(rv,rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; rv = tmpFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0700); - NS_ENSURE_SUCCESS(rv,rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; rv = tmpFile->OpenNSPRFileDesc(PR_RDWR | nsIFile::DELETE_ON_CLOSE, PR_IRWXU, aOutFileDesc); @@ -146,16 +154,19 @@ public: // service is installed when running in xpcshell, and this interferes with // the fake idle service, causing xpcshell-test failures. mTimer = do_CreateInstance(NS_TIMER_CONTRACTID); - NS_ENSURE_TRUE(mTimer != nullptr, NS_ERROR_FAILURE); + if (NS_WARN_IF(!mTimer)) + return NS_ERROR_FAILURE; nsresult rv = mTimer->Init(this, SCHEDULE_TIMEOUT_MS, nsITimer::TYPE_ONE_SHOT); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; // Register shutdown observer so we can cancel the timer if we shutdown before // the timer runs. nsCOMPtr obsSrv = services::GetObserverService(); - NS_ENSURE_TRUE(obsSrv != nullptr, NS_ERROR_FAILURE); + if (NS_WARN_IF(!obsSrv)) + return NS_ERROR_FAILURE; return obsSrv->AddObserver(this, XPCOM_SHUTDOWN_TOPIC, false); } @@ -211,7 +222,8 @@ public: void RemoveAnonTempFileFiles() { nsCOMPtr tmpDir; nsresult rv = GetTempDir(getter_AddRefs(tmpDir)); - NS_ENSURE_SUCCESS_VOID(rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return; // Remove the directory recursively. tmpDir->Remove(true); diff --git a/xpcom/io/nsAppFileLocationProvider.cpp b/xpcom/io/nsAppFileLocationProvider.cpp index b0243c514e7..c0f77437c7a 100644 --- a/xpcom/io/nsAppFileLocationProvider.cpp +++ b/xpcom/io/nsAppFileLocationProvider.cpp @@ -87,10 +87,12 @@ NS_IMPL_ISUPPORTS2(nsAppFileLocationProvider, nsIDirectoryServiceProvider, nsIDi NS_IMETHODIMP nsAppFileLocationProvider::GetFile(const char *prop, bool *persistent, nsIFile **_retval) { + if (NS_WARN_IF(!prop)) + return NS_ERROR_INVALID_ARG; + nsCOMPtr localFile; nsresult rv = NS_ERROR_FAILURE; - NS_ENSURE_ARG(prop); *_retval = nullptr; *persistent = true; @@ -250,7 +252,8 @@ nsAppFileLocationProvider::GetFile(const char *prop, bool *persistent, nsIFile * NS_METHOD nsAppFileLocationProvider::CloneMozBinDirectory(nsIFile **aLocalFile) { - NS_ENSURE_ARG_POINTER(aLocalFile); + if (NS_WARN_IF(!aLocalFile)) + return NS_ERROR_INVALID_ARG; nsresult rv; if (!mMozBinDirectory) @@ -291,7 +294,8 @@ NS_METHOD nsAppFileLocationProvider::CloneMozBinDirectory(nsIFile **aLocalFile) //---------------------------------------------------------------------------------------- NS_METHOD nsAppFileLocationProvider::GetProductDirectory(nsIFile **aLocalFile, bool aLocal) { - NS_ENSURE_ARG_POINTER(aLocalFile); + if (NS_WARN_IF(!aLocalFile)) + return NS_ERROR_INVALID_ARG; nsresult rv; bool exists; @@ -352,7 +356,8 @@ NS_METHOD nsAppFileLocationProvider::GetProductDirectory(nsIFile **aLocalFile, b //---------------------------------------------------------------------------------------- NS_METHOD nsAppFileLocationProvider::GetDefaultUserProfileRoot(nsIFile **aLocalFile, bool aLocal) { - NS_ENSURE_ARG_POINTER(aLocalFile); + if (NS_WARN_IF(!aLocalFile)) + return NS_ERROR_INVALID_ARG; nsresult rv; nsCOMPtr localDir; @@ -416,7 +421,8 @@ class nsAppDirectoryEnumerator : public nsISimpleEnumerator NS_IMETHOD GetNext(nsISupports **result) { - NS_ENSURE_ARG_POINTER(result); + if (NS_WARN_IF(!result)) + return NS_ERROR_INVALID_ARG; *result = nullptr; bool hasMore; @@ -511,7 +517,8 @@ class nsPathsDirectoryEnumerator : public nsAppDirectoryEnumerator NS_IMETHODIMP nsAppFileLocationProvider::GetFiles(const char *prop, nsISimpleEnumerator **_retval) { - NS_ENSURE_ARG_POINTER(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; *_retval = nullptr; nsresult rv = NS_ERROR_FAILURE; diff --git a/xpcom/io/nsBinaryStream.cpp b/xpcom/io/nsBinaryStream.cpp index e3917845870..67784f9eea5 100644 --- a/xpcom/io/nsBinaryStream.cpp +++ b/xpcom/io/nsBinaryStream.cpp @@ -34,21 +34,24 @@ NS_IMPL_ISUPPORTS3(nsBinaryOutputStream, nsIObjectOutputStream, nsIBinaryOutputS NS_IMETHODIMP nsBinaryOutputStream::Flush() { - NS_ENSURE_STATE(mOutputStream); + if (NS_WARN_IF(!mOutputStream)) + return NS_ERROR_UNEXPECTED; return mOutputStream->Flush(); } NS_IMETHODIMP nsBinaryOutputStream::Close() { - NS_ENSURE_STATE(mOutputStream); + if (NS_WARN_IF(!mOutputStream)) + return NS_ERROR_UNEXPECTED; return mOutputStream->Close(); } NS_IMETHODIMP nsBinaryOutputStream::Write(const char *aBuf, uint32_t aCount, uint32_t *aActualBytes) { - NS_ENSURE_STATE(mOutputStream); + if (NS_WARN_IF(!mOutputStream)) + return NS_ERROR_UNEXPECTED; return mOutputStream->Write(aBuf, aCount, aActualBytes); } @@ -69,14 +72,16 @@ nsBinaryOutputStream::WriteSegments(nsReadSegmentFun reader, void * closure, uin NS_IMETHODIMP nsBinaryOutputStream::IsNonBlocking(bool *aNonBlocking) { - NS_ENSURE_STATE(mOutputStream); + if (NS_WARN_IF(!mOutputStream)) + return NS_ERROR_UNEXPECTED; return mOutputStream->IsNonBlocking(aNonBlocking); } nsresult nsBinaryOutputStream::WriteFully(const char *aBuf, uint32_t aCount) { - NS_ENSURE_STATE(mOutputStream); + if (NS_WARN_IF(!mOutputStream)) + return NS_ERROR_UNEXPECTED; nsresult rv; uint32_t bytesWritten; @@ -91,7 +96,8 @@ nsBinaryOutputStream::WriteFully(const char *aBuf, uint32_t aCount) NS_IMETHODIMP nsBinaryOutputStream::SetOutputStream(nsIOutputStream *aOutputStream) { - NS_ENSURE_ARG_POINTER(aOutputStream); + if (NS_WARN_IF(!aOutputStream)) + return NS_ERROR_INVALID_ARG; mOutputStream = aOutputStream; mBufferAccess = do_QueryInterface(aOutputStream); return NS_OK; @@ -245,23 +251,25 @@ nsBinaryOutputStream::WriteCompoundObject(nsISupports* aObject, const nsIID& aIID, bool aIsStrongRef) { - // Can't deal with weak refs - NS_ENSURE_TRUE(aIsStrongRef, NS_ERROR_UNEXPECTED); - nsCOMPtr classInfo = do_QueryInterface(aObject); - NS_ENSURE_TRUE(classInfo, NS_ERROR_NOT_AVAILABLE); - nsCOMPtr serializable = do_QueryInterface(aObject); - NS_ENSURE_TRUE(serializable, NS_ERROR_NOT_AVAILABLE); + + // Can't deal with weak refs + if (NS_WARN_IF(!aIsStrongRef)) + return NS_ERROR_UNEXPECTED; + if (NS_WARN_IF(!classInfo) || NS_WARN_IF(!serializable)) + return NS_ERROR_NOT_AVAILABLE; nsCID cid; classInfo->GetClassIDNoAlloc(&cid); nsresult rv = WriteID(cid); - NS_ENSURE_SUCCESS(rv, rv); - + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; + rv = WriteID(aIID); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; return serializable->Write(this); } @@ -270,17 +278,21 @@ NS_IMETHODIMP nsBinaryOutputStream::WriteID(const nsIID& aIID) { nsresult rv = Write32(aIID.m0); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; rv = Write16(aIID.m1); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; rv = Write16(aIID.m2); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; for (int i = 0; i < 8; ++i) { rv = Write8(aIID.m3[i]); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; } return NS_OK; @@ -306,14 +318,16 @@ NS_IMPL_ISUPPORTS3(nsBinaryInputStream, nsIObjectInputStream, nsIBinaryInputStre NS_IMETHODIMP nsBinaryInputStream::Available(uint64_t* aResult) { - NS_ENSURE_STATE(mInputStream); + if (NS_WARN_IF(!mInputStream)) + return NS_ERROR_UNEXPECTED; return mInputStream->Available(aResult); } NS_IMETHODIMP nsBinaryInputStream::Read(char* aBuffer, uint32_t aCount, uint32_t *aNumRead) { - NS_ENSURE_STATE(mInputStream); + if (NS_WARN_IF(!mInputStream)) + return NS_ERROR_UNEXPECTED; // mInputStream might give us short reads, so deal with that. uint32_t totalRead = 0; @@ -383,7 +397,8 @@ ReadSegmentForwardingThunk(nsIInputStream* aStream, NS_IMETHODIMP nsBinaryInputStream::ReadSegments(nsWriteSegmentFun writer, void * closure, uint32_t count, uint32_t *_retval) { - NS_ENSURE_STATE(mInputStream); + if (NS_WARN_IF(!mInputStream)) + return NS_ERROR_UNEXPECTED; ReadSegmentsClosure thunkClosure = { this, closure, writer, NS_OK, 0 }; @@ -416,21 +431,24 @@ nsBinaryInputStream::ReadSegments(nsWriteSegmentFun writer, void * closure, uint NS_IMETHODIMP nsBinaryInputStream::IsNonBlocking(bool *aNonBlocking) { - NS_ENSURE_STATE(mInputStream); + if (NS_WARN_IF(!mInputStream)) + return NS_ERROR_UNEXPECTED; return mInputStream->IsNonBlocking(aNonBlocking); } NS_IMETHODIMP -nsBinaryInputStream::Close() -{ - NS_ENSURE_STATE(mInputStream); - return mInputStream->Close(); +nsBinaryInputStream::Close() +{ + if (NS_WARN_IF(!mInputStream)) + return NS_ERROR_UNEXPECTED; + return mInputStream->Close(); } NS_IMETHODIMP nsBinaryInputStream::SetInputStream(nsIInputStream *aInputStream) { - NS_ENSURE_ARG_POINTER(aInputStream); + if (NS_WARN_IF(!aInputStream)) + return NS_ERROR_INVALID_ARG; mInputStream = aInputStream; mBufferAccess = do_QueryInterface(aInputStream); return NS_OK; @@ -729,7 +747,8 @@ nsBinaryInputStream::ReadArrayBuffer(uint32_t aLength, const JS::Value& aBuffer, uint32_t bytesRead; nsresult rv = Read(reinterpret_cast(data), aLength, &bytesRead); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; if (bytesRead != aLength) { return NS_ERROR_FAILURE; } @@ -742,10 +761,12 @@ nsBinaryInputStream::ReadObject(bool aIsStrongRef, nsISupports* *aObject) nsCID cid; nsIID iid; nsresult rv = ReadID(&cid); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; rv = ReadID(&iid); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; // HACK: Intercept old (pre-gecko6) nsIURI IID, and replace with // the updated IID, so that we're QI'ing to an actual interface. @@ -774,13 +795,16 @@ nsBinaryInputStream::ReadObject(bool aIsStrongRef, nsISupports* *aObject) // END HACK nsCOMPtr object = do_CreateInstance(cid, &rv); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; nsCOMPtr serializable = do_QueryInterface(object); - NS_ENSURE_TRUE(serializable, NS_ERROR_UNEXPECTED); + if (NS_WARN_IF(!serializable)) + return NS_ERROR_UNEXPECTED; rv = serializable->Read(this); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; return object->QueryInterface(iid, reinterpret_cast(aObject)); } @@ -789,17 +813,21 @@ NS_IMETHODIMP nsBinaryInputStream::ReadID(nsID *aResult) { nsresult rv = Read32(&aResult->m0); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; rv = Read16(&aResult->m1); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; rv = Read16(&aResult->m2); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; for (int i = 0; i < 8; ++i) { rv = Read8(&aResult->m3[i]); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; } return NS_OK; diff --git a/xpcom/io/nsDirectoryService.cpp b/xpcom/io/nsDirectoryService.cpp index 603c9c015ca..a1078d4dfb9 100644 --- a/xpcom/io/nsDirectoryService.cpp +++ b/xpcom/io/nsDirectoryService.cpp @@ -59,7 +59,8 @@ nsresult nsDirectoryService::GetCurrentProcessDirectory(nsIFile** aFile) //---------------------------------------------------------------------------------------- { - NS_ENSURE_ARG_POINTER(aFile); + if (NS_WARN_IF(!aFile)) + return NS_ERROR_INVALID_ARG; *aFile = nullptr; // Set the component registry location: @@ -225,8 +226,10 @@ nsDirectoryService::nsDirectoryService() nsresult nsDirectoryService::Create(nsISupports *outer, REFNSIID aIID, void **aResult) { - NS_ENSURE_ARG_POINTER(aResult); - NS_ENSURE_NO_AGGREGATION(outer); + if (NS_WARN_IF(!aResult)) + return NS_ERROR_INVALID_ARG; + if (NS_WARN_IF(outer)) + return NS_ERROR_NO_AGGREGATION; if (!gService) { @@ -284,7 +287,8 @@ NS_IMPL_ISUPPORTS4(nsDirectoryService, nsIProperties, nsIDirectoryService, nsIDi NS_IMETHODIMP nsDirectoryService::Undefine(const char* prop) { - NS_ENSURE_ARG(prop); + if (NS_WARN_IF(!prop)) + return NS_ERROR_INVALID_ARG; nsDependentCString key(prop); if (!mHashtable.Get(key, nullptr)) @@ -360,7 +364,8 @@ static bool FindProviderFile(nsIDirectoryServiceProvider* aElement, NS_IMETHODIMP nsDirectoryService::Get(const char* prop, const nsIID & uuid, void* *result) { - NS_ENSURE_ARG(prop); + if (NS_WARN_IF(!prop)) + return NS_ERROR_INVALID_ARG; nsDependentCString key(prop); @@ -409,7 +414,8 @@ nsDirectoryService::Get(const char* prop, const nsIID & uuid, void* *result) NS_IMETHODIMP nsDirectoryService::Set(const char* prop, nsISupports* value) { - NS_ENSURE_ARG(prop); + if (NS_WARN_IF(!prop)) + return NS_ERROR_INVALID_ARG; nsDependentCString key(prop); if (mHashtable.Get(key, nullptr) || !value) { @@ -431,7 +437,8 @@ nsDirectoryService::Set(const char* prop, nsISupports* value) NS_IMETHODIMP nsDirectoryService::Has(const char *prop, bool *_retval) { - NS_ENSURE_ARG(prop); + if (NS_WARN_IF(!prop)) + return NS_ERROR_INVALID_ARG; *_retval = false; nsCOMPtr value; @@ -910,7 +917,8 @@ nsDirectoryService::GetFile(const char *prop, bool *persistent, nsIFile **_retva NS_IMETHODIMP nsDirectoryService::GetFiles(const char *prop, nsISimpleEnumerator **_retval) { - NS_ENSURE_ARG_POINTER(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; *_retval = nullptr; return NS_ERROR_FAILURE; diff --git a/xpcom/io/nsIOUtil.cpp b/xpcom/io/nsIOUtil.cpp index 4363355de1a..e4062793b0b 100644 --- a/xpcom/io/nsIOUtil.cpp +++ b/xpcom/io/nsIOUtil.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -13,7 +13,8 @@ NS_IMPL_ISUPPORTS1(nsIOUtil, nsIIOUtil) NS_IMETHODIMP nsIOUtil::InputStreamIsBuffered(nsIInputStream* aStream, bool* _retval) { - NS_ENSURE_ARG_POINTER(aStream); + if (NS_WARN_IF(!aStream)) + return NS_ERROR_INVALID_ARG; *_retval = NS_InputStreamIsBuffered(aStream); return NS_OK; } @@ -21,7 +22,8 @@ nsIOUtil::InputStreamIsBuffered(nsIInputStream* aStream, bool* _retval) NS_IMETHODIMP nsIOUtil::OutputStreamIsBuffered(nsIOutputStream* aStream, bool* _retval) { - NS_ENSURE_ARG_POINTER(aStream); + if (NS_WARN_IF(!aStream)) + return NS_ERROR_INVALID_ARG; *_retval = NS_OutputStreamIsBuffered(aStream); return NS_OK; } diff --git a/xpcom/io/nsInputStreamTee.cpp b/xpcom/io/nsInputStreamTee.cpp index 08202d41004..b1c4094120a 100644 --- a/xpcom/io/nsInputStreamTee.cpp +++ b/xpcom/io/nsInputStreamTee.cpp @@ -164,7 +164,6 @@ nsInputStreamTee::TeeSegment(const char *buf, uint32_t count) } nsRefPtr event = new nsInputStreamTeeWriteEvent(buf, count, mSink, this); - NS_ENSURE_TRUE(event, NS_ERROR_OUT_OF_MEMORY); LOG(("nsInputStreamTee::TeeSegment [%p] dispatching write %u bytes\n", this, count)); return mEventTarget->Dispatch(event, NS_DISPATCH_NORMAL); @@ -214,7 +213,8 @@ NS_IMPL_ISUPPORTS2(nsInputStreamTee, NS_IMETHODIMP nsInputStreamTee::Close() { - NS_ENSURE_TRUE(mSource, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mSource)) + return NS_ERROR_NOT_INITIALIZED; nsresult rv = mSource->Close(); mSource = 0; mSink = 0; @@ -224,14 +224,16 @@ nsInputStreamTee::Close() NS_IMETHODIMP nsInputStreamTee::Available(uint64_t *avail) { - NS_ENSURE_TRUE(mSource, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mSource)) + return NS_ERROR_NOT_INITIALIZED; return mSource->Available(avail); } NS_IMETHODIMP nsInputStreamTee::Read(char *buf, uint32_t count, uint32_t *bytesRead) { - NS_ENSURE_TRUE(mSource, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mSource)) + return NS_ERROR_NOT_INITIALIZED; nsresult rv = mSource->Read(buf, count, bytesRead); if (NS_FAILED(rv) || (*bytesRead == 0)) @@ -246,7 +248,8 @@ nsInputStreamTee::ReadSegments(nsWriteSegmentFun writer, uint32_t count, uint32_t *bytesRead) { - NS_ENSURE_TRUE(mSource, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mSource)) + return NS_ERROR_NOT_INITIALIZED; mWriter = writer; mClosure = closure; @@ -257,7 +260,8 @@ nsInputStreamTee::ReadSegments(nsWriteSegmentFun writer, NS_IMETHODIMP nsInputStreamTee::IsNonBlocking(bool *result) { - NS_ENSURE_TRUE(mSource, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mSource)) + return NS_ERROR_NOT_INITIALIZED; return mSource->IsNonBlocking(result); } diff --git a/xpcom/io/nsLocalFileCommon.cpp b/xpcom/io/nsLocalFileCommon.cpp index 5ec4bae22b3..75c53483877 100644 --- a/xpcom/io/nsLocalFileCommon.cpp +++ b/xpcom/io/nsLocalFileCommon.cpp @@ -33,7 +33,8 @@ void NS_ShutdownLocalFile() NS_IMETHODIMP nsLocalFile::InitWithFile(nsIFile *aFile) { - NS_ENSURE_ARG(aFile); + if (NS_WARN_IF(!aFile)) + return NS_ERROR_INVALID_ARG; nsAutoCString path; aFile->GetNativePath(path); @@ -189,7 +190,8 @@ static int32_t SplitPath(PRUnichar *path, PRUnichar **nodeArray, int32_t arrayLe NS_IMETHODIMP nsLocalFile::GetRelativeDescriptor(nsIFile *fromFile, nsACString& _retval) { - NS_ENSURE_ARG_POINTER(fromFile); + if (NS_WARN_IF(!fromFile)) + return NS_ERROR_INVALID_ARG; const int32_t kMaxNodesInPath = 32; // diff --git a/xpcom/io/nsLocalFileUnix.cpp b/xpcom/io/nsLocalFileUnix.cpp index 099bcea9028..c0127e80949 100644 --- a/xpcom/io/nsLocalFileUnix.cpp +++ b/xpcom/io/nsLocalFileUnix.cpp @@ -243,8 +243,10 @@ nsLocalFile::nsLocalFileConstructor(nsISupports *outer, const nsIID &aIID, void **aInstancePtr) { - NS_ENSURE_ARG_POINTER(aInstancePtr); - NS_ENSURE_NO_AGGREGATION(outer); + if (NS_WARN_IF(!aInstancePtr)) + return NS_ERROR_INVALID_ARG; + if (NS_WARN_IF(outer)) + return NS_ERROR_NO_AGGREGATION; *aInstancePtr = nullptr; @@ -1005,7 +1007,8 @@ NS_IMETHODIMP nsLocalFile::GetLastModifiedTime(PRTime *aLastModTime) { CHECK_mPath(); - NS_ENSURE_ARG(aLastModTime); + if (NS_WARN_IF(!aLastModTime)) + return NS_ERROR_INVALID_ARG; PRFileInfo64 info; if (PR_GetFileInfo64(mPath.get(), &info) != PR_SUCCESS) @@ -1043,7 +1046,8 @@ NS_IMETHODIMP nsLocalFile::GetLastModifiedTimeOfLink(PRTime *aLastModTimeOfLink) { CHECK_mPath(); - NS_ENSURE_ARG(aLastModTimeOfLink); + if (NS_WARN_IF(!aLastModTimeOfLink)) + return NS_ERROR_INVALID_ARG; struct STAT sbuf; if (LSTAT(mPath.get(), &sbuf) == -1) @@ -1072,7 +1076,8 @@ nsLocalFile::SetLastModifiedTimeOfLink(PRTime aLastModTimeOfLink) NS_IMETHODIMP nsLocalFile::GetPermissions(uint32_t *aPermissions) { - NS_ENSURE_ARG(aPermissions); + if (NS_WARN_IF(!aPermissions)) + return NS_ERROR_INVALID_ARG; ENSURE_STAT_CACHE(); *aPermissions = NORMALIZE_PERMS(mCachedStat.st_mode); return NS_OK; @@ -1082,7 +1087,8 @@ NS_IMETHODIMP nsLocalFile::GetPermissionsOfLink(uint32_t *aPermissionsOfLink) { CHECK_mPath(); - NS_ENSURE_ARG(aPermissionsOfLink); + if (NS_WARN_IF(!aPermissionsOfLink)) + return NS_ERROR_INVALID_ARG; struct STAT sbuf; if (LSTAT(mPath.get(), &sbuf) == -1) @@ -1127,7 +1133,8 @@ nsLocalFile::SetPermissionsOfLink(uint32_t aPermissions) NS_IMETHODIMP nsLocalFile::GetFileSize(int64_t *aFileSize) { - NS_ENSURE_ARG_POINTER(aFileSize); + if (NS_WARN_IF(!aFileSize)) + return NS_ERROR_INVALID_ARG; *aFileSize = 0; ENSURE_STAT_CACHE(); @@ -1176,7 +1183,8 @@ NS_IMETHODIMP nsLocalFile::GetFileSizeOfLink(int64_t *aFileSize) { CHECK_mPath(); - NS_ENSURE_ARG(aFileSize); + if (NS_WARN_IF(!aFileSize)) + return NS_ERROR_INVALID_ARG; struct STAT sbuf; if (LSTAT(mPath.get(), &sbuf) == -1) @@ -1241,7 +1249,8 @@ GetDeviceName(int deviceMajor, int deviceMinor, nsACString &deviceName) NS_IMETHODIMP nsLocalFile::GetDiskSpaceAvailable(int64_t *aDiskSpaceAvailable) { - NS_ENSURE_ARG_POINTER(aDiskSpaceAvailable); + if (NS_WARN_IF(!aDiskSpaceAvailable)) + return NS_ERROR_INVALID_ARG; // These systems have the operations necessary to check disk space. @@ -1326,7 +1335,8 @@ NS_IMETHODIMP nsLocalFile::GetParent(nsIFile **aParent) { CHECK_mPath(); - NS_ENSURE_ARG_POINTER(aParent); + if (NS_WARN_IF(!aParent)) + return NS_ERROR_INVALID_ARG; *aParent = nullptr; // if '/' we are at the top of the volume, return null @@ -1372,7 +1382,8 @@ NS_IMETHODIMP nsLocalFile::Exists(bool *_retval) { CHECK_mPath(); - NS_ENSURE_ARG_POINTER(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; *_retval = (access(mPath.get(), F_OK) == 0); return NS_OK; @@ -1383,7 +1394,8 @@ NS_IMETHODIMP nsLocalFile::IsWritable(bool *_retval) { CHECK_mPath(); - NS_ENSURE_ARG_POINTER(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; *_retval = (access(mPath.get(), W_OK) == 0); if (*_retval || errno == EACCES) @@ -1395,7 +1407,8 @@ NS_IMETHODIMP nsLocalFile::IsReadable(bool *_retval) { CHECK_mPath(); - NS_ENSURE_ARG_POINTER(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; *_retval = (access(mPath.get(), R_OK) == 0); if (*_retval || errno == EACCES) @@ -1407,7 +1420,8 @@ NS_IMETHODIMP nsLocalFile::IsExecutable(bool *_retval) { CHECK_mPath(); - NS_ENSURE_ARG_POINTER(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; // Check extension (bug 663899). On certain platforms, the file // extension may cause the OS to treat it as executable regardless of @@ -1496,7 +1510,8 @@ nsLocalFile::IsExecutable(bool *_retval) NS_IMETHODIMP nsLocalFile::IsDirectory(bool *_retval) { - NS_ENSURE_ARG_POINTER(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; *_retval = false; ENSURE_STAT_CACHE(); *_retval = S_ISDIR(mCachedStat.st_mode); @@ -1506,7 +1521,8 @@ nsLocalFile::IsDirectory(bool *_retval) NS_IMETHODIMP nsLocalFile::IsFile(bool *_retval) { - NS_ENSURE_ARG_POINTER(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; *_retval = false; ENSURE_STAT_CACHE(); *_retval = S_ISREG(mCachedStat.st_mode); @@ -1516,7 +1532,8 @@ nsLocalFile::IsFile(bool *_retval) NS_IMETHODIMP nsLocalFile::IsHidden(bool *_retval) { - NS_ENSURE_ARG_POINTER(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; nsACString::const_iterator begin, end; LocateNativeLeafName(begin, end); *_retval = (*begin == '.'); @@ -1526,7 +1543,8 @@ nsLocalFile::IsHidden(bool *_retval) NS_IMETHODIMP nsLocalFile::IsSymlink(bool *_retval) { - NS_ENSURE_ARG_POINTER(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; CHECK_mPath(); struct STAT symStat; @@ -1539,7 +1557,8 @@ nsLocalFile::IsSymlink(bool *_retval) NS_IMETHODIMP nsLocalFile::IsSpecial(bool *_retval) { - NS_ENSURE_ARG_POINTER(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; ENSURE_STAT_CACHE(); *_retval = S_ISCHR(mCachedStat.st_mode) || S_ISBLK(mCachedStat.st_mode) || @@ -1554,8 +1573,10 @@ nsLocalFile::IsSpecial(bool *_retval) NS_IMETHODIMP nsLocalFile::Equals(nsIFile *inFile, bool *_retval) { - NS_ENSURE_ARG(inFile); - NS_ENSURE_ARG_POINTER(_retval); + if (NS_WARN_IF(!inFile)) + return NS_ERROR_INVALID_ARG; + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; *_retval = false; nsAutoCString inPath; @@ -1573,8 +1594,10 @@ NS_IMETHODIMP nsLocalFile::Contains(nsIFile *inFile, bool recur, bool *_retval) { CHECK_mPath(); - NS_ENSURE_ARG(inFile); - NS_ENSURE_ARG_POINTER(_retval); + if (NS_WARN_IF(!inFile)) + return NS_ERROR_INVALID_ARG; + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; nsAutoCString inPath; nsresult rv; @@ -1710,7 +1733,8 @@ NS_IMETHODIMP nsLocalFile::Load(PRLibrary **_retval) { CHECK_mPath(); - NS_ENSURE_ARG_POINTER(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; #ifdef NS_BUILD_REFCNT_LOGGING nsTraceRefcntImpl::SetActivityIsLegal(false); @@ -2121,7 +2145,8 @@ nsLocalFile::InitWithCFURL(CFURLRef aCFURL) NS_IMETHODIMP nsLocalFile::InitWithFSRef(const FSRef *aFSRef) { - NS_ENSURE_ARG(aFSRef); + if (NS_WARN_IF(!aFSRef)) + return NS_ERROR_INVALID_ARG; CFURLRef newURLRef = ::CFURLCreateFromFSRef(kCFAllocatorDefault, aFSRef); if (newURLRef) { @@ -2151,7 +2176,8 @@ nsLocalFile::GetCFURL(CFURLRef *_retval) NS_IMETHODIMP nsLocalFile::GetFSRef(FSRef *_retval) { - NS_ENSURE_ARG_POINTER(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; nsresult rv = NS_ERROR_FAILURE; @@ -2169,7 +2195,8 @@ nsLocalFile::GetFSRef(FSRef *_retval) NS_IMETHODIMP nsLocalFile::GetFSSpec(FSSpec *_retval) { - NS_ENSURE_ARG_POINTER(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; FSRef fsRef; nsresult rv = GetFSRef(&fsRef); @@ -2184,7 +2211,8 @@ nsLocalFile::GetFSSpec(FSSpec *_retval) NS_IMETHODIMP nsLocalFile::GetFileSizeWithResFork(int64_t *aFileSizeWithResFork) { - NS_ENSURE_ARG_POINTER(aFileSizeWithResFork); + if (NS_WARN_IF(!aFileSizeWithResFork)) + return NS_ERROR_INVALID_ARG; FSRef fsRef; nsresult rv = GetFSRef(&fsRef); @@ -2343,7 +2371,8 @@ nsLocalFile::OpenDocWithApp(nsIFile *aAppToOpenWith, bool aLaunchInBackground) NS_IMETHODIMP nsLocalFile::IsPackage(bool *_retval) { - NS_ENSURE_ARG(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; *_retval = false; CFURLRef url; @@ -2414,7 +2443,8 @@ NS_IMETHODIMP nsLocalFile::GetBundleContentsLastModifiedTime(int64_t *aLastModTime) { CHECK_mPath(); - NS_ENSURE_ARG_POINTER(aLastModTime); + if (NS_WARN_IF(!aLastModTime)) + return NS_ERROR_INVALID_ARG; bool isPackage = false; nsresult rv = IsPackage(&isPackage); @@ -2440,7 +2470,8 @@ nsLocalFile::GetBundleContentsLastModifiedTime(int64_t *aLastModTime) NS_IMETHODIMP nsLocalFile::InitWithFile(nsIFile *aFile) { - NS_ENSURE_ARG(aFile); + if (NS_WARN_IF(!aFile)) + return NS_ERROR_INVALID_ARG; nsAutoCString nativePath; nsresult rv = aFile->GetNativePath(nativePath); diff --git a/xpcom/io/nsLocalFileWin.cpp b/xpcom/io/nsLocalFileWin.cpp index c8cd7911f15..3d1e3e01ab0 100644 --- a/xpcom/io/nsLocalFileWin.cpp +++ b/xpcom/io/nsLocalFileWin.cpp @@ -725,7 +725,8 @@ struct nsDir static nsresult OpenDir(const nsAFlatString &name, nsDir * *dir) { - NS_ENSURE_ARG_POINTER(dir); + if (NS_WARN_IF(!dir)) + return NS_ERROR_INVALID_ARG; *dir = nullptr; if (name.Length() + 3 >= MAX_PATH) @@ -765,7 +766,8 @@ static nsresult ReadDir(nsDir *dir, PRDirFlags flags, nsString& name) { name.Truncate(); - NS_ENSURE_ARG(dir); + if (NS_WARN_IF(!dir)) + return NS_ERROR_INVALID_ARG; while (1) { BOOL rv; @@ -809,7 +811,8 @@ ReadDir(nsDir *dir, PRDirFlags flags, nsString& name) static nsresult CloseDir(nsDir *&d) { - NS_ENSURE_ARG(d); + if (NS_WARN_IF(!d)) + return NS_ERROR_INVALID_ARG; BOOL isOk = FindClose(d->handle); // PR_DELETE also nulls out the passed in pointer. @@ -962,8 +965,10 @@ nsLocalFile::nsLocalFile() nsresult nsLocalFile::nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr) { - NS_ENSURE_ARG_POINTER(aInstancePtr); - NS_ENSURE_NO_AGGREGATION(outer); + if (NS_WARN_IF(!aInstancePtr)) + return NS_ERROR_INVALID_ARG; + if (NS_WARN_IF(outer)) + return NS_ERROR_NO_AGGREGATION; nsLocalFile* inst = new nsLocalFile(); if (inst == nullptr) @@ -1149,7 +1154,8 @@ nsLocalFile::Clone(nsIFile **file) NS_IMETHODIMP nsLocalFile::InitWithFile(nsIFile *aFile) { - NS_ENSURE_ARG(aFile); + if (NS_WARN_IF(!aFile)) + return NS_ERROR_INVALID_ARG; nsAutoString path; aFile->GetPath(path); @@ -2072,7 +2078,8 @@ nsLocalFile::CopyMove(nsIFile *aParentDir, const nsAString &newName, bool follow return NS_ERROR_FAILURE; rv = file->MoveTo(target, EmptyString()); - NS_ENSURE_SUCCESS(rv,rv); + if (NS_FAILED(rv)) + return rv; } else { @@ -2080,7 +2087,8 @@ nsLocalFile::CopyMove(nsIFile *aParentDir, const nsAString &newName, bool follow rv = file->CopyToFollowingLinks(target, EmptyString()); else rv = file->CopyTo(target, EmptyString()); - NS_ENSURE_SUCCESS(rv,rv); + if (NS_FAILED(rv)) + return rv; } } } @@ -2093,7 +2101,8 @@ nsLocalFile::CopyMove(nsIFile *aParentDir, const nsAString &newName, bool follow if (move) { rv = Remove(false /* recursive */); - NS_ENSURE_SUCCESS(rv,rv); + if (NS_FAILED(rv)) + return rv; } } @@ -2258,7 +2267,8 @@ nsLocalFile::GetLastModifiedTime(PRTime *aLastModifiedTime) // Check we are correctly initialized. CHECK_mWorkingPath(); - NS_ENSURE_ARG(aLastModifiedTime); + if (NS_WARN_IF(!aLastModifiedTime)) + return NS_ERROR_INVALID_ARG; // get the modified time of the target as determined by mFollowSymlinks // If true, then this will be for the target of the shortcut file, @@ -2281,7 +2291,8 @@ nsLocalFile::GetLastModifiedTimeOfLink(PRTime *aLastModifiedTime) // Check we are correctly initialized. CHECK_mWorkingPath(); - NS_ENSURE_ARG(aLastModifiedTime); + if (NS_WARN_IF(!aLastModifiedTime)) + return NS_ERROR_INVALID_ARG; // The caller is assumed to have already called IsSymlink // and to have found that this file is a link. @@ -2381,7 +2392,8 @@ nsLocalFile::SetModDate(PRTime aLastModifiedTime, const PRUnichar *filePath) NS_IMETHODIMP nsLocalFile::GetPermissions(uint32_t *aPermissions) { - NS_ENSURE_ARG(aPermissions); + if (NS_WARN_IF(!aPermissions)) + return NS_ERROR_INVALID_ARG; // get the permissions of the target as determined by mFollowSymlinks // If true, then this will be for the target of the shortcut file, @@ -2410,7 +2422,8 @@ nsLocalFile::GetPermissionsOfLink(uint32_t *aPermissions) // Check we are correctly initialized. CHECK_mWorkingPath(); - NS_ENSURE_ARG(aPermissions); + if (NS_WARN_IF(!aPermissions)) + return NS_ERROR_INVALID_ARG; // The caller is assumed to have already called IsSymlink // and to have found that this file is a link. It is not @@ -2479,7 +2492,8 @@ nsLocalFile::SetPermissionsOfLink(uint32_t aPermissions) NS_IMETHODIMP nsLocalFile::GetFileSize(int64_t *aFileSize) { - NS_ENSURE_ARG(aFileSize); + if (NS_WARN_IF(!aFileSize)) + return NS_ERROR_INVALID_ARG; nsresult rv = ResolveAndStat(); if (NS_FAILED(rv)) @@ -2496,7 +2510,8 @@ nsLocalFile::GetFileSizeOfLink(int64_t *aFileSize) // Check we are correctly initialized. CHECK_mWorkingPath(); - NS_ENSURE_ARG(aFileSize); + if (NS_WARN_IF(!aFileSize)) + return NS_ERROR_INVALID_ARG; // The caller is assumed to have already called IsSymlink // and to have found that this file is a link. @@ -2551,7 +2566,8 @@ nsLocalFile::GetDiskSpaceAvailable(int64_t *aDiskSpaceAvailable) // Check we are correctly initialized. CHECK_mWorkingPath(); - NS_ENSURE_ARG(aDiskSpaceAvailable); + if (NS_WARN_IF(!aDiskSpaceAvailable)) + return NS_ERROR_INVALID_ARG; ResolveAndStat(); @@ -2580,7 +2596,8 @@ nsLocalFile::GetParent(nsIFile * *aParent) // Check we are correctly initialized. CHECK_mWorkingPath(); - NS_ENSURE_ARG_POINTER(aParent); + if (NS_WARN_IF(!aParent)) + return NS_ERROR_INVALID_ARG; // A two-character path must be a drive such as C:, so it has no parent if (mWorkingPath.Length() == 2) { @@ -2624,7 +2641,8 @@ nsLocalFile::Exists(bool *_retval) // Check we are correctly initialized. CHECK_mWorkingPath(); - NS_ENSURE_ARG(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; *_retval = false; MakeDirty(); @@ -2694,7 +2712,8 @@ nsLocalFile::IsReadable(bool *_retval) // Check we are correctly initialized. CHECK_mWorkingPath(); - NS_ENSURE_ARG(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; *_retval = false; nsresult rv = ResolveAndStat(); @@ -2712,7 +2731,8 @@ nsLocalFile::IsExecutable(bool *_retval) // Check we are correctly initialized. CHECK_mWorkingPath(); - NS_ENSURE_ARG(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; *_retval = false; nsresult rv; @@ -2867,7 +2887,8 @@ nsLocalFile::IsHidden(bool *_retval) nsresult nsLocalFile::HasFileAttribute(DWORD fileAttrib, bool *_retval) { - NS_ENSURE_ARG(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; nsresult rv = Resolve(); if (NS_FAILED(rv)) { @@ -2889,7 +2910,8 @@ nsLocalFile::IsSymlink(bool *_retval) // Check we are correctly initialized. CHECK_mWorkingPath(); - NS_ENSURE_ARG(_retval); + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; // unless it is a valid shortcut path it's not a symlink if (!IsShortcutPath(mWorkingPath)) { @@ -2920,8 +2942,10 @@ nsLocalFile::IsSpecial(bool *_retval) NS_IMETHODIMP nsLocalFile::Equals(nsIFile *inFile, bool *_retval) { - NS_ENSURE_ARG(inFile); - NS_ENSURE_ARG(_retval); + if (NS_WARN_IF(!inFile)) + return NS_ERROR_INVALID_ARG; + if (NS_WARN_IF(!_retval)) + return NS_ERROR_INVALID_ARG; EnsureShortPath(); diff --git a/xpcom/io/nsMultiplexInputStream.cpp b/xpcom/io/nsMultiplexInputStream.cpp index 2373cfaa737..4d36fb90721 100644 --- a/xpcom/io/nsMultiplexInputStream.cpp +++ b/xpcom/io/nsMultiplexInputStream.cpp @@ -118,7 +118,6 @@ nsMultiplexInputStream::InsertStream(nsIInputStream *aStream, uint32_t aIndex) { NS_ASSERTION(SeekableStreamAtBeginning(aStream), "Inserted stream not at beginning."); bool result = mStreams.InsertElementAt(aIndex, aStream); - NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY); if (mCurrentStream > aIndex || (mCurrentStream == aIndex && mStartedReadingCurrent)) ++mCurrentStream; @@ -143,7 +142,8 @@ NS_IMETHODIMP nsMultiplexInputStream::GetStream(uint32_t aIndex, nsIInputStream **_retval) { *_retval = mStreams.SafeElementAt(aIndex, nullptr); - NS_ENSURE_TRUE(*_retval, NS_ERROR_NOT_AVAILABLE); + if (NS_WARN_IF(!*_retval)) + return NS_ERROR_NOT_AVAILABLE; NS_ADDREF(*_retval); return NS_OK; @@ -181,7 +181,8 @@ nsMultiplexInputStream::Available(uint64_t *_retval) for (uint32_t i = mCurrentStream; i < len; i++) { uint64_t streamAvail; rv = mStreams[i]->Available(&streamAvail); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; avail += streamAvail; } *_retval = avail; @@ -328,7 +329,8 @@ nsMultiplexInputStream::IsNonBlocking(bool *aNonBlocking) } for (uint32_t i = 0; i < len; ++i) { nsresult rv = mStreams[i]->IsNonBlocking(aNonBlocking); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; // If one is non-blocking the entire stream becomes non-blocking // (except that we don't implement nsIAsyncInputStream, so there's // not much for the caller to do if Read returns "would block") @@ -367,7 +369,8 @@ nsMultiplexInputStream::Seek(int32_t aWhence, int64_t aOffset) if (i < oldCurrentStream || (i == oldCurrentStream && oldStartedReadingCurrent)) { rv = stream->Seek(NS_SEEK_SET, 0); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; continue; } else { @@ -383,13 +386,15 @@ nsMultiplexInputStream::Seek(int32_t aWhence, int64_t aOffset) } else { rv = stream->Tell(&streamPos); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; } // See if we need to seek current stream forward or backward if (remaining < streamPos) { rv = stream->Seek(NS_SEEK_SET, remaining); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; mCurrentStream = i; mStartedReadingCurrent = remaining != 0; @@ -405,12 +410,14 @@ nsMultiplexInputStream::Seek(int32_t aWhence, int64_t aOffset) else { uint64_t avail; rv = mStreams[i]->Available(&avail); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; int64_t newPos = XPCOM_MIN(remaining, streamPos + (int64_t)avail); rv = stream->Seek(NS_SEEK_SET, newPos); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; mCurrentStream = i; mStartedReadingCurrent = true; @@ -436,12 +443,14 @@ nsMultiplexInputStream::Seek(int32_t aWhence, int64_t aOffset) uint64_t avail; rv = mStreams[i]->Available(&avail); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; int64_t seek = XPCOM_MIN((int64_t)avail, remaining); rv = stream->Seek(NS_SEEK_CUR, seek); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; mCurrentStream = i; mStartedReadingCurrent = true; @@ -460,12 +469,14 @@ nsMultiplexInputStream::Seek(int32_t aWhence, int64_t aOffset) int64_t pos; rv = stream->Tell(&pos); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; int64_t seek = XPCOM_MIN(pos, remaining); rv = stream->Seek(NS_SEEK_CUR, -seek); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; mCurrentStream = i; mStartedReadingCurrent = seek != -pos; @@ -495,7 +506,8 @@ nsMultiplexInputStream::Seek(int32_t aWhence, int64_t aOffset) if (remaining == 0) { if (i >= oldCurrentStream) { rv = stream->Seek(NS_SEEK_END, 0); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; } else { break; @@ -509,7 +521,8 @@ nsMultiplexInputStream::Seek(int32_t aWhence, int64_t aOffset) } else { uint64_t avail; rv = mStreams[i]->Available(&avail); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; streamPos = avail; } @@ -517,7 +530,8 @@ nsMultiplexInputStream::Seek(int32_t aWhence, int64_t aOffset) // See if we have enough data in the current stream. if (DeprecatedAbs(remaining) < streamPos) { rv = stream->Seek(NS_SEEK_END, remaining); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; mCurrentStream = i; mStartedReadingCurrent = true; @@ -531,12 +545,14 @@ nsMultiplexInputStream::Seek(int32_t aWhence, int64_t aOffset) } else { int64_t avail; rv = stream->Tell(&avail); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; int64_t newPos = streamPos + XPCOM_MIN(avail, DeprecatedAbs(remaining)); rv = stream->Seek(NS_SEEK_END, -newPos); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; mCurrentStream = i; mStartedReadingCurrent = true; @@ -570,11 +586,13 @@ nsMultiplexInputStream::Tell(int64_t *_retval) last = mStartedReadingCurrent ? mCurrentStream+1 : mCurrentStream; for (i = 0; i < last; ++i) { nsCOMPtr stream = do_QueryInterface(mStreams[i]); - NS_ENSURE_TRUE(stream, NS_ERROR_NO_INTERFACE); + if (NS_WARN_IF(!stream)) + return NS_ERROR_NO_INTERFACE; int64_t pos; rv = stream->Tell(&pos); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; ret64 += pos; } *_retval = ret64; diff --git a/xpcom/io/nsPipe3.cpp b/xpcom/io/nsPipe3.cpp index eb63ef92432..4c988cf083b 100644 --- a/xpcom/io/nsPipe3.cpp +++ b/xpcom/io/nsPipe3.cpp @@ -356,7 +356,8 @@ nsPipe::GetInputStream(nsIAsyncInputStream **aInputStream) NS_IMETHODIMP nsPipe::GetOutputStream(nsIAsyncOutputStream **aOutputStream) { - NS_ENSURE_TRUE(mInited, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mInited)) + return NS_ERROR_NOT_INITIALIZED; NS_ADDREF(*aOutputStream = &mOutput); return NS_OK; } diff --git a/xpcom/io/nsStorageStream.cpp b/xpcom/io/nsStorageStream.cpp index 1bf82156757..5c745819b5b 100644 --- a/xpcom/io/nsStorageStream.cpp +++ b/xpcom/io/nsStorageStream.cpp @@ -88,8 +88,10 @@ NS_IMETHODIMP nsStorageStream::GetOutputStream(int32_t aStartingOffset, nsIOutputStream * *aOutputStream) { - NS_ENSURE_ARG(aOutputStream); - NS_ENSURE_TRUE(mSegmentedBuffer, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!aOutputStream)) + return NS_ERROR_INVALID_ARG; + if (NS_WARN_IF(!mSegmentedBuffer)) + return NS_ERROR_NOT_INITIALIZED; if (mWriteInProgress) return NS_ERROR_NOT_AVAILABLE; @@ -116,7 +118,8 @@ nsStorageStream::GetOutputStream(int32_t aStartingOffset, NS_IMETHODIMP nsStorageStream::Close() { - NS_ENSURE_TRUE(mSegmentedBuffer, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mSegmentedBuffer)) + return NS_ERROR_NOT_INITIALIZED; mWriteInProgress = false; @@ -145,15 +148,15 @@ nsStorageStream::Flush() NS_IMETHODIMP nsStorageStream::Write(const char *aBuffer, uint32_t aCount, uint32_t *aNumWritten) { - NS_ENSURE_TRUE(mSegmentedBuffer, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!aNumWritten) || NS_WARN_IF(!aBuffer)) + return NS_ERROR_INVALID_ARG; + if (NS_WARN_IF(!mSegmentedBuffer)) + return NS_ERROR_NOT_INITIALIZED; const char* readCursor; uint32_t count, availableInSegment, remaining; nsresult rv = NS_OK; - NS_ENSURE_ARG_POINTER(aNumWritten); - NS_ENSURE_ARG(aBuffer); - LOG(("nsStorageStream [%p] Write mWriteCursor=%x mSegmentEnd=%x aCount=%d\n", this, mWriteCursor, mSegmentEnd, aCount)); @@ -223,7 +226,6 @@ nsStorageStream::IsNonBlocking(bool *aNonBlocking) NS_IMETHODIMP nsStorageStream::GetLength(uint32_t *aLength) { - NS_ENSURE_ARG(aLength); *aLength = mLogicalLength; return NS_OK; } @@ -232,7 +234,8 @@ nsStorageStream::GetLength(uint32_t *aLength) NS_IMETHODIMP nsStorageStream::SetLength(uint32_t aLength) { - NS_ENSURE_TRUE(mSegmentedBuffer, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mSegmentedBuffer)) + return NS_ERROR_NOT_INITIALIZED; if (mWriteInProgress) return NS_ERROR_NOT_AVAILABLE; @@ -257,8 +260,6 @@ nsStorageStream::SetLength(uint32_t aLength) NS_IMETHODIMP nsStorageStream::GetWriteInProgress(bool *aWriteInProgress) { - NS_ENSURE_ARG(aWriteInProgress); - *aWriteInProgress = mWriteInProgress; return NS_OK; } @@ -266,7 +267,8 @@ nsStorageStream::GetWriteInProgress(bool *aWriteInProgress) NS_METHOD nsStorageStream::Seek(int32_t aPosition) { - NS_ENSURE_TRUE(mSegmentedBuffer, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mSegmentedBuffer)) + return NS_ERROR_NOT_INITIALIZED; // An argument of -1 means "seek to end of stream" if (aPosition == -1) @@ -358,7 +360,8 @@ NS_IMPL_ISUPPORTS2(nsStorageInputStream, NS_IMETHODIMP nsStorageStream::NewInputStream(int32_t aStartingOffset, nsIInputStream* *aInputStream) { - NS_ENSURE_TRUE(mSegmentedBuffer, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mSegmentedBuffer)) + return NS_ERROR_NOT_INITIALIZED; nsStorageInputStream *inputStream = new nsStorageInputStream(this, mSegmentSize); if (!inputStream) @@ -524,8 +527,6 @@ nsStorageInputStream::Seek(uint32_t aPosition) nsresult NS_NewStorageStream(uint32_t segmentSize, uint32_t maxSize, nsIStorageStream **result) { - NS_ENSURE_ARG(result); - nsStorageStream* storageStream = new nsStorageStream(); if (!storageStream) return NS_ERROR_OUT_OF_MEMORY; diff --git a/xpcom/io/nsStringStream.cpp b/xpcom/io/nsStringStream.cpp index f3281781192..f6bfd18d9f7 100644 --- a/xpcom/io/nsStringStream.cpp +++ b/xpcom/io/nsStringStream.cpp @@ -112,7 +112,8 @@ nsStringInputStream::GetData(nsACString &data) // The stream doesn't have any data when it is closed. We could fake it // and return an empty string here, but it seems better to keep this return // value consistent with the behavior of the other 'getter' methods. - NS_ENSURE_TRUE(!Closed(), NS_BASE_STREAM_CLOSED); + if (NS_WARN_IF(Closed())) + return NS_BASE_STREAM_CLOSED; data.Assign(mData); return NS_OK; @@ -140,7 +141,8 @@ nsStringInputStream::ToString(char **result) NS_IMETHODIMP nsStringInputStream::SetData(const char *data, int32_t dataLen) { - NS_ENSURE_ARG_POINTER(data); + if (NS_WARN_IF(!data)) + return NS_ERROR_INVALID_ARG; mData.Assign(data, dataLen); mOffset = 0; return NS_OK; @@ -149,7 +151,8 @@ nsStringInputStream::SetData(const char *data, int32_t dataLen) NS_IMETHODIMP nsStringInputStream::AdoptData(char *data, int32_t dataLen) { - NS_ENSURE_ARG_POINTER(data); + if (NS_WARN_IF(!data)) + return NS_ERROR_INVALID_ARG; mData.Adopt(data, dataLen); mOffset = 0; return NS_OK; @@ -158,7 +161,8 @@ nsStringInputStream::AdoptData(char *data, int32_t dataLen) NS_IMETHODIMP nsStringInputStream::ShareData(const char *data, int32_t dataLen) { - NS_ENSURE_ARG_POINTER(data); + if (NS_WARN_IF(!data)) + return NS_ERROR_INVALID_ARG; if (dataLen < 0) dataLen = strlen(data); @@ -262,8 +266,8 @@ nsStringInputStream::Seek(int32_t whence, int64_t offset) return NS_ERROR_INVALID_ARG; } - NS_ENSURE_ARG(newPos >= 0); - NS_ENSURE_ARG(newPos <= Length()); + if (NS_WARN_IF(newPos < 0) || NS_WARN_IF(newPos > Length())) + return NS_ERROR_INVALID_ARG; mOffset = (uint32_t)newPos; return NS_OK; @@ -386,7 +390,8 @@ nsStringInputStreamConstructor(nsISupports *outer, REFNSIID iid, void **result) { *result = nullptr; - NS_ENSURE_TRUE(!outer, NS_ERROR_NO_AGGREGATION); + if (NS_WARN_IF(outer)) + return NS_ERROR_NO_AGGREGATION; nsStringInputStream *inst = new nsStringInputStream(); if (!inst) diff --git a/xpcom/reflect/xptcall/src/xptcall.cpp b/xpcom/reflect/xptcall/src/xptcall.cpp index e46ddd559d3..a33b1e70051 100644 --- a/xpcom/reflect/xptcall/src/xptcall.cpp +++ b/xpcom/reflect/xptcall/src/xptcall.cpp @@ -40,11 +40,13 @@ EXPORT_XPCOM_API(nsresult) NS_GetXPTCallStub(REFNSIID aIID, nsIXPTCProxy* aOuter, nsISomeInterface* *aResult) { - NS_ENSURE_ARG(aOuter && aResult); + if (NS_WARN_IF(!aOuter) || NS_WARN_IF(!aResult)) + return NS_ERROR_INVALID_ARG; XPTInterfaceInfoManager *iim = XPTInterfaceInfoManager::GetSingleton(); - NS_ENSURE_TRUE(iim, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!iim)) + return NS_ERROR_NOT_INITIALIZED; xptiInterfaceEntry *iie = iim->GetInterfaceEntryForIID(&aIID); if (!iie || !iie->EnsureResolved() || iie->GetBuiltinClassFlag()) diff --git a/xpcom/threads/LazyIdleThread.cpp b/xpcom/threads/LazyIdleThread.cpp index 0cf14ad0acd..71bf2ea5371 100644 --- a/xpcom/threads/LazyIdleThread.cpp +++ b/xpcom/threads/LazyIdleThread.cpp @@ -147,21 +147,26 @@ LazyIdleThread::EnsureThread() if (mShutdownMethod == AutomaticShutdown && NS_IsMainThread()) { nsCOMPtr obs = do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; rv = obs->AddObserver(this, "xpcom-shutdown-threads", false); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; } mIdleTimer = do_CreateInstance(NS_TIMER_CONTRACTID, &rv); - NS_ENSURE_TRUE(mIdleTimer, NS_ERROR_FAILURE); + if (NS_WARN_IF(!mIdleTimer)) + return NS_ERROR_UNEXPECTED; nsCOMPtr runnable = NS_NewRunnableMethod(this, &LazyIdleThread::InitThread); - NS_ENSURE_TRUE(runnable, NS_ERROR_FAILURE); + if (NS_WARN_IF(!runnable)) + return NS_ERROR_UNEXPECTED; rv = NS_NewThread(getter_AddRefs(mThread), runnable); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; return NS_OK; } @@ -268,12 +273,14 @@ LazyIdleThread::ShutdownThread() nsCOMPtr runnable = NS_NewRunnableMethod(this, &LazyIdleThread::CleanupThread); - NS_ENSURE_TRUE(runnable, NS_ERROR_FAILURE); + if (NS_WARN_IF(!runnable)) + return NS_ERROR_UNEXPECTED; PreDispatch(); rv = mThread->Dispatch(runnable, NS_DISPATCH_NORMAL); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; // Put the temporary queue in place before calling Shutdown(). mQueuedRunnables = &queuedRunnables; @@ -299,7 +306,8 @@ LazyIdleThread::ShutdownThread() if (mIdleTimer) { rv = mIdleTimer->Cancel(); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; mIdleTimer = nullptr; } @@ -376,7 +384,8 @@ LazyIdleThread::Dispatch(nsIRunnable* aEvent, ASSERT_OWNING_THREAD(); // LazyIdleThread can't always support synchronous dispatch currently. - NS_ENSURE_TRUE(aFlags == NS_DISPATCH_NORMAL, NS_ERROR_NOT_IMPLEMENTED); + if (NS_WARN_IF(aFlags != NS_DISPATCH_NORMAL)) + return NS_ERROR_NOT_IMPLEMENTED; // If our thread is shutting down then we can't actually dispatch right now. // Queue this runnable for later. @@ -386,7 +395,8 @@ LazyIdleThread::Dispatch(nsIRunnable* aEvent, } nsresult rv = EnsureThread(); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; PreDispatch(); @@ -427,7 +437,8 @@ LazyIdleThread::Shutdown() mIdleObserver = nullptr; - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; return NS_OK; } @@ -467,7 +478,8 @@ LazyIdleThread::Notify(nsITimer* aTimer) } nsresult rv = ShutdownThread(); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; return NS_OK; } @@ -513,10 +525,12 @@ LazyIdleThread::AfterProcessNextEvent(nsIThreadInternal* /* aThread */, if (shouldNotifyIdle) { nsCOMPtr runnable = NS_NewRunnableMethod(this, &LazyIdleThread::ScheduleTimer); - NS_ENSURE_TRUE(runnable, NS_ERROR_FAILURE); + if (NS_WARN_IF(!runnable)) + return NS_ERROR_UNEXPECTED; nsresult rv = mOwningThread->Dispatch(runnable, NS_DISPATCH_NORMAL); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; } return NS_OK; diff --git a/xpcom/threads/nsEnvironment.cpp b/xpcom/threads/nsEnvironment.cpp index f5c0656b4ed..53b20755673 100644 --- a/xpcom/threads/nsEnvironment.cpp +++ b/xpcom/threads/nsEnvironment.cpp @@ -48,7 +48,8 @@ nsEnvironment::Exists(const nsAString& aName, bool *aOutValue) { nsAutoCString nativeName; nsresult rv = NS_CopyUnicodeToNative(aName, nativeName); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; nsAutoCString nativeVal; #if defined(XP_UNIX) @@ -78,7 +79,8 @@ nsEnvironment::Get(const nsAString& aName, nsAString& aOutValue) { nsAutoCString nativeName; nsresult rv = NS_CopyUnicodeToNative(aName, nativeName); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; nsAutoCString nativeVal; const char *value = PR_GetEnv(nativeName.get()); @@ -122,10 +124,12 @@ nsEnvironment::Set(const nsAString& aName, const nsAString& aValue) nsAutoCString nativeVal; nsresult rv = NS_CopyUnicodeToNative(aName, nativeName); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; rv = NS_CopyUnicodeToNative(aValue, nativeVal); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; MutexAutoLock lock(mLock); diff --git a/xpcom/threads/nsMemoryPressure.cpp b/xpcom/threads/nsMemoryPressure.cpp index 0e1b556054e..094d4c06ab0 100644 --- a/xpcom/threads/nsMemoryPressure.cpp +++ b/xpcom/threads/nsMemoryPressure.cpp @@ -49,6 +49,5 @@ NS_DispatchMemoryPressure(MemoryPressureState state) { NS_DispatchEventualMemoryPressure(state); nsCOMPtr event = new nsRunnable; - NS_ENSURE_TRUE(event, NS_ERROR_OUT_OF_MEMORY); return NS_DispatchToMainThread(event); } diff --git a/xpcom/threads/nsProcessCommon.cpp b/xpcom/threads/nsProcessCommon.cpp index 8a6345d11d3..d2d660bafb6 100644 --- a/xpcom/threads/nsProcessCommon.cpp +++ b/xpcom/threads/nsProcessCommon.cpp @@ -88,7 +88,8 @@ nsProcess::Init(nsIFile* executable) if (mExecutable) return NS_ERROR_ALREADY_INITIALIZED; - NS_ENSURE_ARG_POINTER(executable); + if (NS_WARN_IF(!executable)) + return NS_ERROR_INVALID_ARG; bool isFile; //First make sure the file exists @@ -408,8 +409,10 @@ nsresult nsProcess::RunProcess(bool blocking, char **my_argv, nsIObserver* observer, bool holdWeak, bool argsUTF8) { - NS_ENSURE_TRUE(mExecutable, NS_ERROR_NOT_INITIALIZED); - NS_ENSURE_FALSE(mThread, NS_ERROR_ALREADY_INITIALIZED); + if (NS_WARN_IF(!mExecutable)) + return NS_ERROR_NOT_INITIALIZED; + if (NS_WARN_IF(mThread)) + return NS_ERROR_ALREADY_INITIALIZED; if (observer) { if (holdWeak) { diff --git a/xpcom/threads/nsThread.cpp b/xpcom/threads/nsThread.cpp index 94e8a04da13..9cc4e2528e8 100644 --- a/xpcom/threads/nsThread.cpp +++ b/xpcom/threads/nsThread.cpp @@ -152,9 +152,9 @@ NS_IMPL_CI_INTERFACE_GETTER4(nsThread, nsIThread, nsIThreadInternal, class nsThreadStartupEvent : public nsRunnable { public: - // Create a new thread startup object. - static nsThreadStartupEvent *Create() { - return new nsThreadStartupEvent(); + nsThreadStartupEvent() + : mMon("nsThreadStartupEvent.mMon") + , mInitialized(false) { } // This method does not return until the thread startup object is in the @@ -180,11 +180,6 @@ private: return NS_OK; } - nsThreadStartupEvent() - : mMon("nsThreadStartupEvent.mMon") - , mInitialized(false) { - } - ReentrantMonitor mMon; bool mInitialized; }; @@ -310,8 +305,7 @@ nsresult nsThread::Init() { // spawn thread and wait until it is fully setup - nsRefPtr startup = nsThreadStartupEvent::Create(); - NS_ENSURE_TRUE(startup, NS_ERROR_OUT_OF_MEMORY); + nsRefPtr startup = new nsThreadStartupEvent(); NS_ADDREF_THIS(); @@ -377,7 +371,8 @@ nsThread::Dispatch(nsIRunnable *event, uint32_t flags) { LOG(("THRD(%p) Dispatch [%p %x]\n", this, event, flags)); - NS_ENSURE_ARG_POINTER(event); + if (NS_WARN_IF(!event)) + return NS_ERROR_INVALID_ARG; if (gXPCOMThreadsShutDown && MAIN_THREAD != mIsMainThread) { return NS_ERROR_ILLEGAL_DURING_SHUTDOWN; @@ -385,7 +380,8 @@ nsThread::Dispatch(nsIRunnable *event, uint32_t flags) if (flags & DISPATCH_SYNC) { nsThread *thread = nsThreadManager::get()->GetCurrentThread(); - NS_ENSURE_STATE(thread); + if (NS_WARN_IF(!thread)) + return NS_ERROR_NOT_AVAILABLE; // XXX we should be able to do something better here... we should // be able to monitor the slot occupied by this event and use @@ -437,7 +433,8 @@ nsThread::Shutdown() if (!mThread) return NS_OK; - NS_ENSURE_STATE(mThread != PR_GetCurrentThread()); + if (NS_WARN_IF(mThread == PR_GetCurrentThread())) + return NS_ERROR_UNEXPECTED; // Prevent multiple calls to this method { @@ -490,7 +487,8 @@ nsThread::Shutdown() NS_IMETHODIMP nsThread::HasPendingEvents(bool *result) { - NS_ENSURE_STATE(PR_GetCurrentThread() == mThread); + if (NS_WARN_IF(PR_GetCurrentThread() != mThread)) + return NS_ERROR_NOT_SAME_THREAD; *result = mEvents.GetEvent(false, nullptr); return NS_OK; @@ -548,7 +546,8 @@ nsThread::ProcessNextEvent(bool mayWait, bool *result) { LOG(("THRD(%p) ProcessNextEvent [%u %u]\n", this, mayWait, mRunningEvent)); - NS_ENSURE_STATE(PR_GetCurrentThread() == mThread); + if (NS_WARN_IF(PR_GetCurrentThread() != mThread)) + return NS_ERROR_NOT_SAME_THREAD; if (MAIN_THREAD == mIsMainThread && mayWait && !ShuttingDown()) HangMonitor::Suspend(); @@ -644,7 +643,8 @@ nsThread::GetPriority(int32_t *priority) NS_IMETHODIMP nsThread::SetPriority(int32_t priority) { - NS_ENSURE_STATE(mThread); + if (NS_WARN_IF(!mThread)) + return NS_ERROR_NOT_INITIALIZED; // NSPR defines the following four thread priorities: // PR_PRIORITY_LOW @@ -690,7 +690,8 @@ nsThread::GetObserver(nsIThreadObserver **obs) NS_IMETHODIMP nsThread::SetObserver(nsIThreadObserver *obs) { - NS_ENSURE_STATE(PR_GetCurrentThread() == mThread); + if (NS_WARN_IF(PR_GetCurrentThread() != mThread)) + return NS_ERROR_NOT_SAME_THREAD; MutexAutoLock lock(mLock); mObserver = obs; @@ -700,8 +701,8 @@ nsThread::SetObserver(nsIThreadObserver *obs) NS_IMETHODIMP nsThread::GetRecursionDepth(uint32_t *depth) { - NS_ENSURE_ARG_POINTER(depth); - NS_ENSURE_STATE(PR_GetCurrentThread() == mThread); + if (NS_WARN_IF(PR_GetCurrentThread() != mThread)) + return NS_ERROR_NOT_SAME_THREAD; *depth = mRunningEvent; return NS_OK; @@ -710,8 +711,10 @@ nsThread::GetRecursionDepth(uint32_t *depth) NS_IMETHODIMP nsThread::AddObserver(nsIThreadObserver *observer) { - NS_ENSURE_ARG_POINTER(observer); - NS_ENSURE_STATE(PR_GetCurrentThread() == mThread); + if (NS_WARN_IF(!observer)) + return NS_ERROR_INVALID_ARG; + if (NS_WARN_IF(PR_GetCurrentThread() != mThread)) + return NS_ERROR_NOT_SAME_THREAD; NS_WARN_IF_FALSE(!mEventObservers.Contains(observer), "Adding an observer twice!"); @@ -727,7 +730,8 @@ nsThread::AddObserver(nsIThreadObserver *observer) NS_IMETHODIMP nsThread::RemoveObserver(nsIThreadObserver *observer) { - NS_ENSURE_STATE(PR_GetCurrentThread() == mThread); + if (NS_WARN_IF(PR_GetCurrentThread() != mThread)) + return NS_ERROR_NOT_SAME_THREAD; if (observer && !mEventObservers.RemoveElement(observer)) { NS_WARNING("Removing an observer that was never added!"); diff --git a/xpcom/threads/nsThreadManager.cpp b/xpcom/threads/nsThreadManager.cpp index 52d1364f695..cf41dcdb49a 100644 --- a/xpcom/threads/nsThreadManager.cpp +++ b/xpcom/threads/nsThreadManager.cpp @@ -217,7 +217,8 @@ nsThreadManager::NewThread(uint32_t creationFlags, nsIThread **result) { // No new threads during Shutdown - NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mInitialized)) + return NS_ERROR_NOT_INITIALIZED; nsThread *thr = new nsThread(nsThread::NOT_MAIN_THREAD, stackSize); if (!thr) @@ -242,8 +243,10 @@ NS_IMETHODIMP nsThreadManager::GetThreadFromPRThread(PRThread *thread, nsIThread **result) { // Keep this functioning during Shutdown - NS_ENSURE_TRUE(mMainThread, NS_ERROR_NOT_INITIALIZED); - NS_ENSURE_ARG_POINTER(thread); + if (NS_WARN_IF(!mMainThread)) + return NS_ERROR_NOT_INITIALIZED; + if (NS_WARN_IF(!thread)) + return NS_ERROR_INVALID_ARG; nsRefPtr temp; { @@ -259,7 +262,8 @@ NS_IMETHODIMP nsThreadManager::GetMainThread(nsIThread **result) { // Keep this functioning during Shutdown - NS_ENSURE_TRUE(mMainThread, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mMainThread)) + return NS_ERROR_NOT_INITIALIZED; NS_ADDREF(*result = mMainThread); return NS_OK; } @@ -268,7 +272,8 @@ NS_IMETHODIMP nsThreadManager::GetCurrentThread(nsIThread **result) { // Keep this functioning during Shutdown - NS_ENSURE_TRUE(mMainThread, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!mMainThread)) + return NS_ERROR_NOT_INITIALIZED; *result = GetCurrentThread(); if (!*result) return NS_ERROR_OUT_OF_MEMORY; diff --git a/xpcom/threads/nsThreadPool.cpp b/xpcom/threads/nsThreadPool.cpp index 2ccc4b0142f..6e3236db7a7 100644 --- a/xpcom/threads/nsThreadPool.cpp +++ b/xpcom/threads/nsThreadPool.cpp @@ -92,7 +92,8 @@ nsThreadPool::PutEvent(nsIRunnable *event) nsThreadManager::get()->NewThread(0, nsIThreadManager::DEFAULT_STACK_SIZE, getter_AddRefs(thread)); - NS_ENSURE_STATE(thread); + if (NS_WARN_IF(!thread)) + return NS_ERROR_UNEXPECTED; bool killThread = false; { @@ -225,12 +226,14 @@ nsThreadPool::Dispatch(nsIRunnable *event, uint32_t flags) { LOG(("THRD-P(%p) dispatch [%p %x]\n", this, event, flags)); - NS_ENSURE_STATE(!mShutdown); + if (NS_WARN_IF(mShutdown)) + return NS_ERROR_NOT_AVAILABLE; if (flags & DISPATCH_SYNC) { nsCOMPtr thread; nsThreadManager::get()->GetCurrentThread(getter_AddRefs(thread)); - NS_ENSURE_STATE(thread); + if (NS_WARN_IF(!thread)) + return NS_ERROR_NOT_AVAILABLE; nsRefPtr wrapper = new nsThreadSyncDispatch(thread, event); diff --git a/xpcom/threads/nsTimerImpl.cpp b/xpcom/threads/nsTimerImpl.cpp index bb59fc98bf1..3aa9e606e24 100644 --- a/xpcom/threads/nsTimerImpl.cpp +++ b/xpcom/threads/nsTimerImpl.cpp @@ -317,14 +317,16 @@ nsresult nsTimerImpl::InitCommon(uint32_t aType, uint32_t aDelay) { nsresult rv; - NS_ENSURE_TRUE(gThread, NS_ERROR_NOT_INITIALIZED); + if (NS_WARN_IF(!gThread)) + return NS_ERROR_NOT_INITIALIZED; if (!mEventTarget) { NS_ERROR("mEventTarget is NULL"); return NS_ERROR_NOT_INITIALIZED; } rv = gThread->Init(); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(NS_FAILED(rv))) + return rv; /** * In case of re-Init, both with and without a preceding Cancel, clear the @@ -357,7 +359,8 @@ NS_IMETHODIMP nsTimerImpl::InitWithFuncCallback(nsTimerCallbackFunc aFunc, uint32_t aDelay, uint32_t aType) { - NS_ENSURE_ARG_POINTER(aFunc); + if (NS_WARN_IF(!aFunc)) + return NS_ERROR_INVALID_ARG; ReleaseCallback(); mCallbackType = CALLBACK_TYPE_FUNC; @@ -371,7 +374,8 @@ NS_IMETHODIMP nsTimerImpl::InitWithCallback(nsITimerCallback *aCallback, uint32_t aDelay, uint32_t aType) { - NS_ENSURE_ARG_POINTER(aCallback); + if (NS_WARN_IF(!aCallback)) + return NS_ERROR_INVALID_ARG; ReleaseCallback(); mCallbackType = CALLBACK_TYPE_INTERFACE; @@ -385,7 +389,8 @@ NS_IMETHODIMP nsTimerImpl::Init(nsIObserver *aObserver, uint32_t aDelay, uint32_t aType) { - NS_ENSURE_ARG_POINTER(aObserver); + if (NS_WARN_IF(!aObserver)) + return NS_ERROR_INVALID_ARG; ReleaseCallback(); mCallbackType = CALLBACK_TYPE_OBSERVER; @@ -481,8 +486,8 @@ NS_IMETHODIMP nsTimerImpl::GetTarget(nsIEventTarget** aTarget) NS_IMETHODIMP nsTimerImpl::SetTarget(nsIEventTarget* aTarget) { - NS_ENSURE_TRUE(mCallbackType == CALLBACK_TYPE_UNKNOWN, - NS_ERROR_ALREADY_INITIALIZED); + if (NS_WARN_IF(mCallbackType != CALLBACK_TYPE_UNKNOWN)) + return NS_ERROR_ALREADY_INITIALIZED; if (aTarget) mEventTarget = aTarget;