From 3a2258a4f2221808f9e2da97a1de83e548c8d2a1 Mon Sep 17 00:00:00 2001 From: "reed%reedloden.com" Date: Fri, 19 Oct 2007 23:26:53 +0000 Subject: [PATCH] Bug 398435 - "PRBool misuse bugs in xpcom/" [p=taras r=bsmedberg a1.9=sayrer] git-svn-id: svn://10.0.0.236/trunk@237940 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/ds/nsHashtable.cpp | 2 +- mozilla/xpcom/glue/nsBaseHashtable.h | 2 +- mozilla/xpcom/glue/nsTHashtable.h | 2 +- mozilla/xpcom/glue/nsThreadUtils.cpp | 4 ++-- mozilla/xpcom/io/nsBinaryStream.cpp | 2 +- mozilla/xpcom/io/nsEscape.cpp | 18 +++++++++--------- mozilla/xpcom/io/nsPipe3.cpp | 2 +- mozilla/xpcom/io/nsScriptableInputStream.cpp | 2 +- mozilla/xpcom/proxy/src/nsProxyEvent.cpp | 2 +- mozilla/xpcom/proxy/src/nsProxyEventPrivate.h | 2 +- mozilla/xpcom/reflect/xptinfo/public/xptinfo.h | 2 +- .../xpcom/reflect/xptinfo/src/xptiManifest.cpp | 16 ++++++++-------- mozilla/xpcom/typelib/xpt/public/xpt_struct.h | 4 ++-- 13 files changed, 30 insertions(+), 30 deletions(-) diff --git a/mozilla/xpcom/ds/nsHashtable.cpp b/mozilla/xpcom/ds/nsHashtable.cpp index 7afddf4a2b0..4566000ff31 100644 --- a/mozilla/xpcom/ds/nsHashtable.cpp +++ b/mozilla/xpcom/ds/nsHashtable.cpp @@ -795,7 +795,7 @@ nsObjectHashtable::RemoveAndDelete(nsHashKey *aKey) { void *value = Remove(aKey); if (value && mDestroyElementFun) - return (*mDestroyElementFun)(aKey, value, mDestroyElementClosure); + return !!(*mDestroyElementFun)(aKey, value, mDestroyElementClosure); return PR_FALSE; } diff --git a/mozilla/xpcom/glue/nsBaseHashtable.h b/mozilla/xpcom/glue/nsBaseHashtable.h index 566dcb92fe1..48e9fd8f3b2 100644 --- a/mozilla/xpcom/glue/nsBaseHashtable.h +++ b/mozilla/xpcom/glue/nsBaseHashtable.h @@ -103,7 +103,7 @@ public: * This function is especially useful for static hashtables. * @return PR_TRUE if the table has been initialized. */ - PRBool IsInitialized() const { return this->mTable.entrySize; } + PRBool IsInitialized() const { return !!this->mTable.entrySize; } /** * Return the number of entries in the table. diff --git a/mozilla/xpcom/glue/nsTHashtable.h b/mozilla/xpcom/glue/nsTHashtable.h index fd4ee26c0df..a06efea333f 100644 --- a/mozilla/xpcom/glue/nsTHashtable.h +++ b/mozilla/xpcom/glue/nsTHashtable.h @@ -128,7 +128,7 @@ public: * Check whether the table has been initialized. This can be useful for static hashtables. * @return the initialization state of the class. */ - PRBool IsInitialized() const { return mTable.entrySize; } + PRBool IsInitialized() const { return !!mTable.entrySize; } /** * KeyType is typedef'ed for ease of use. diff --git a/mozilla/xpcom/glue/nsThreadUtils.cpp b/mozilla/xpcom/glue/nsThreadUtils.cpp index e46c6b4459e..0ae127194d7 100644 --- a/mozilla/xpcom/glue/nsThreadUtils.cpp +++ b/mozilla/xpcom/glue/nsThreadUtils.cpp @@ -193,7 +193,7 @@ NS_HasPendingEvents(nsIThread *thread) #ifdef MOZILLA_INTERNAL_API if (!thread) { thread = NS_GetCurrentThread(); - NS_ENSURE_STATE(thread); + NS_ENSURE_TRUE(thread, PR_FALSE); } #else nsCOMPtr current; @@ -213,7 +213,7 @@ NS_ProcessNextEvent(nsIThread *thread, PRBool mayWait) #ifdef MOZILLA_INTERNAL_API if (!thread) { thread = NS_GetCurrentThread(); - NS_ENSURE_STATE(thread); + NS_ENSURE_TRUE(thread, PR_FALSE); } #else nsCOMPtr current; diff --git a/mozilla/xpcom/io/nsBinaryStream.cpp b/mozilla/xpcom/io/nsBinaryStream.cpp index 7beaca20d6d..679299c6217 100644 --- a/mozilla/xpcom/io/nsBinaryStream.cpp +++ b/mozilla/xpcom/io/nsBinaryStream.cpp @@ -475,7 +475,7 @@ nsBinaryInputStream::ReadBoolean(PRBool* aBoolean) { PRUint8 byteResult; nsresult rv = Read8(&byteResult); - *aBoolean = byteResult; + *aBoolean = !!byteResult; return rv; } diff --git a/mozilla/xpcom/io/nsEscape.cpp b/mozilla/xpcom/io/nsEscape.cpp index 139937f6783..063b9357515 100644 --- a/mozilla/xpcom/io/nsEscape.cpp +++ b/mozilla/xpcom/io/nsEscape.cpp @@ -379,11 +379,11 @@ NS_COM PRBool NS_EscapeURL(const char *part, static const char hexChars[] = "0123456789ABCDEF"; if (partLen < 0) partLen = strlen(part); - PRBool forced = (flags & esc_Forced); - PRBool ignoreNonAscii = (flags & esc_OnlyASCII); - PRBool ignoreAscii = (flags & esc_OnlyNonASCII); - PRBool writing = (flags & esc_AlwaysCopy); - PRBool colon = (flags & esc_Colon); + PRBool forced = !!(flags & esc_Forced); + PRBool ignoreNonAscii = !!(flags & esc_OnlyASCII); + PRBool ignoreAscii = !!(flags & esc_OnlyNonASCII); + PRBool writing = !!(flags & esc_AlwaysCopy); + PRBool colon = !!(flags & esc_Colon); register const unsigned char* src = (const unsigned char *) part; @@ -461,10 +461,10 @@ NS_COM PRBool NS_UnescapeURL(const char *str, PRInt32 len, PRUint32 flags, nsACS if (len < 0) len = strlen(str); - PRBool ignoreNonAscii = (flags & esc_OnlyASCII); - PRBool ignoreAscii = (flags & esc_OnlyNonASCII); - PRBool writing = (flags & esc_AlwaysCopy); - PRBool skipControl = (flags & esc_SkipControl); + PRBool ignoreNonAscii = !!(flags & esc_OnlyASCII); + PRBool ignoreAscii = !!(flags & esc_OnlyNonASCII); + PRBool writing = !!(flags & esc_AlwaysCopy); + PRBool skipControl = !!(flags & esc_SkipControl); static const char hexChars[] = "0123456789ABCDEFabcdef"; diff --git a/mozilla/xpcom/io/nsPipe3.cpp b/mozilla/xpcom/io/nsPipe3.cpp index a0d66efc337..2ff7c8a1239 100644 --- a/mozilla/xpcom/io/nsPipe3.cpp +++ b/mozilla/xpcom/io/nsPipe3.cpp @@ -1041,7 +1041,7 @@ nsPipeOutputStream::OnOutputException(nsresult reason, nsPipeEvents &events) LOG(("nsPipeOutputStream::OnOutputException [this=%x reason=%x]\n", this, reason)); - nsresult result = PR_FALSE; + PRBool result = PR_FALSE; NS_ASSERTION(NS_FAILED(reason), "huh? successful exception"); mWritable = PR_FALSE; diff --git a/mozilla/xpcom/io/nsScriptableInputStream.cpp b/mozilla/xpcom/io/nsScriptableInputStream.cpp index 5570daf0c0a..548aaa04500 100644 --- a/mozilla/xpcom/io/nsScriptableInputStream.cpp +++ b/mozilla/xpcom/io/nsScriptableInputStream.cpp @@ -213,7 +213,7 @@ nsScriptableInputStream::ReadBoolean(PRBool* aBoolean) { PRUint8 byteResult; nsresult rv = Read8(&byteResult); - *aBoolean = byteResult; + *aBoolean = !!byteResult; return rv; } diff --git a/mozilla/xpcom/proxy/src/nsProxyEvent.cpp b/mozilla/xpcom/proxy/src/nsProxyEvent.cpp index bee1415f2ee..b6628c1efbd 100644 --- a/mozilla/xpcom/proxy/src/nsProxyEvent.cpp +++ b/mozilla/xpcom/proxy/src/nsProxyEvent.cpp @@ -293,7 +293,7 @@ nsProxyObjectCallInfo::CopyStrings(PRBool copy) PRBool nsProxyObjectCallInfo::GetCompleted() { - return (PRBool)mCompleted; + return !!mCompleted; } void diff --git a/mozilla/xpcom/proxy/src/nsProxyEventPrivate.h b/mozilla/xpcom/proxy/src/nsProxyEventPrivate.h index 80ecbb011fa..9a2c63739ed 100644 --- a/mozilla/xpcom/proxy/src/nsProxyEventPrivate.h +++ b/mozilla/xpcom/proxy/src/nsProxyEventPrivate.h @@ -244,7 +244,7 @@ public: void SetCallersTarget(nsIEventTarget* target); PRBool IsSync() const { - return mOwner->GetProxyType() & NS_PROXY_SYNC; + return !!(mOwner->GetProxyType() & NS_PROXY_SYNC); } private: diff --git a/mozilla/xpcom/reflect/xptinfo/public/xptinfo.h b/mozilla/xpcom/reflect/xptinfo/public/xptinfo.h index f6a5fcfef79..70606ff5f70 100644 --- a/mozilla/xpcom/reflect/xptinfo/public/xptinfo.h +++ b/mozilla/xpcom/reflect/xptinfo/public/xptinfo.h @@ -94,7 +94,7 @@ public: } PRBool IsArray() const - {return (PRBool) TagPart() == T_ARRAY;} + {return TagPart() == T_ARRAY;} // 'Dependent' means that params of this type are dependent upon other // params. e.g. an T_INTERFACE_IS is dependent upon some other param at diff --git a/mozilla/xpcom/reflect/xptinfo/src/xptiManifest.cpp b/mozilla/xpcom/reflect/xptinfo/src/xptiManifest.cpp index f0a28727625..4ac47a4a263 100644 --- a/mozilla/xpcom/reflect/xptinfo/src/xptiManifest.cpp +++ b/mozilla/xpcom/reflect/xptinfo/src/xptiManifest.cpp @@ -102,14 +102,14 @@ xpti_InterfaceWriter(PLDHashTable *table, PLDHashEntryHdr *hdr, const xptiTypelib& typelib = entry->GetTypelibRecord(); - PRBool success = PR_fprintf(fd, "%d,%s,%s,%d,%d,%d\n", - (int) number, - entry->GetTheName(), - iidStr, - (int) typelib.GetFileIndex(), - (int) (typelib.IsZip() ? - typelib.GetZipItemIndex() : -1), - (int) entry->GetScriptableFlag()); + PRBool success = !!PR_fprintf(fd, "%d,%s,%s,%d,%d,%d\n", + (int) number, + entry->GetTheName(), + iidStr, + (int) typelib.GetFileIndex(), + (int) (typelib.IsZip() ? + typelib.GetZipItemIndex() : -1), + (int) entry->GetScriptableFlag()); nsCRT::free(iidStr); diff --git a/mozilla/xpcom/typelib/xpt/public/xpt_struct.h b/mozilla/xpcom/typelib/xpt/public/xpt_struct.h index bcbc706ef63..a5ba3a4b2df 100644 --- a/mozilla/xpcom/typelib/xpt/public/xpt_struct.h +++ b/mozilla/xpcom/typelib/xpt/public/xpt_struct.h @@ -268,8 +268,8 @@ struct XPTInterfaceDescriptor { #define XPT_ID_TAGMASK (~XPT_ID_FLAGMASK) #define XPT_ID_TAG(id) ((id).flags & XPT_ID_TAGMASK) -#define XPT_ID_IS_SCRIPTABLE(flags) (flags & XPT_ID_SCRIPTABLE) -#define XPT_ID_IS_FUNCTION(flags) (flags & XPT_ID_FUNCTION) +#define XPT_ID_IS_SCRIPTABLE(flags) (!!(flags & XPT_ID_SCRIPTABLE)) +#define XPT_ID_IS_FUNCTION(flags) (!!(flags & XPT_ID_FUNCTION)) extern XPT_PUBLIC_API(PRBool) XPT_GetInterfaceIndexByName(XPTInterfaceDirectoryEntry *ide_block,