From df4018141752de57cd7ce59ef556f541016facc1 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Tue, 12 Jul 2011 14:24:14 +0200 Subject: [PATCH 1/7] fix warning on 64bit systems: cast to pointer from integer of different size [-Wint-to-pointer-cast] Signed-off-by: Giel van Schijndel --- src/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.h b/src/util.h index e7110570c..064339f99 100644 --- a/src/util.h +++ b/src/util.h @@ -648,7 +648,7 @@ inline bool TerminateThread(pthread_t hthread, unsigned int nExitCode) return (pthread_cancel(hthread) == 0); } -inline void ExitThread(unsigned int nExitCode) +inline void ExitThread(size_t nExitCode) { pthread_exit((void*)nExitCode); } From ecf1c79aada222ccbf93b0f15d98339431d1a881 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Fri, 24 Jun 2011 19:56:23 +0200 Subject: [PATCH 2/7] fix warnings: expression result unused [-Wunused-value] In the assert()s take advantage of the fact that string constants ("string") are effectively of type 'const char []', which when used in an expression yield a non-NULL pointer. An assertion that should always fail can thus be formulated as: assert(!"fail); An assertion where a text message should be added to the expression can be written as such: assert("message" && expression); Signed-off-by: Giel van Schijndel --- src/db.h | 4 ++-- src/main.cpp | 2 +- src/script.h | 2 +- src/util.h | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/db.h b/src/db.h index a86c110b3..bd8254f7d 100644 --- a/src/db.h +++ b/src/db.h @@ -88,7 +88,7 @@ protected: if (!pdb) return false; if (fReadOnly) - assert(("Write called on database in read-only mode", false)); + assert(!"Write called on database in read-only mode"); // Key CDataStream ssKey(SER_DISK); @@ -117,7 +117,7 @@ protected: if (!pdb) return false; if (fReadOnly) - assert(("Erase called on database in read-only mode", false)); + assert(!"Erase called on database in read-only mode"); // Key CDataStream ssKey(SER_DISK); diff --git a/src/main.cpp b/src/main.cpp index 6e973493a..690219401 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1688,7 +1688,7 @@ string GetWarnings(string strFor) return strStatusBar; else if (strFor == "rpc") return strRPC; - assert(("GetWarnings() : invalid parameter", false)); + assert(!"GetWarnings() : invalid parameter"); return "error"; } diff --git a/src/script.h b/src/script.h index ae9fdfffa..2a36db2fa 100644 --- a/src/script.h +++ b/src/script.h @@ -486,7 +486,7 @@ public: { // I'm not sure if this should push the script or concatenate scripts. // If there's ever a use for pushing a script onto a script, delete this member fn - assert(("warning: pushing a CScript onto a CScript with << is probably not intended, use + to concatenate", false)); + assert(!"warning: pushing a CScript onto a CScript with << is probably not intended, use + to concatenate"); return *this; } diff --git a/src/util.h b/src/util.h index 064339f99..9922ba82a 100644 --- a/src/util.h +++ b/src/util.h @@ -264,7 +264,7 @@ public: // I'd rather be careful than suffer the other more error prone syntax. // The compiler will optimise away all this loop junk. #define CRITICAL_BLOCK(cs) \ - for (bool fcriticalblockonce=true; fcriticalblockonce; assert(("break caught by CRITICAL_BLOCK!", !fcriticalblockonce)), fcriticalblockonce=false) \ + for (bool fcriticalblockonce=true; fcriticalblockonce; assert("break caught by CRITICAL_BLOCK!" && !fcriticalblockonce), fcriticalblockonce=false) \ for (CCriticalBlock criticalblock(cs); fcriticalblockonce && (cs.pszFile=__FILE__, cs.nLine=__LINE__, true); fcriticalblockonce=false, cs.pszFile=NULL, cs.nLine=0) class CTryCriticalBlock @@ -278,7 +278,7 @@ public: }; #define TRY_CRITICAL_BLOCK(cs) \ - for (bool fcriticalblockonce=true; fcriticalblockonce; assert(("break caught by TRY_CRITICAL_BLOCK!", !fcriticalblockonce)), fcriticalblockonce=false) \ + for (bool fcriticalblockonce=true; fcriticalblockonce; assert("break caught by TRY_CRITICAL_BLOCK!" && !fcriticalblockonce), fcriticalblockonce=false) \ for (CTryCriticalBlock criticalblock(cs); fcriticalblockonce && (fcriticalblockonce = criticalblock.Entered()) && (cs.pszFile=__FILE__, cs.nLine=__LINE__, true); fcriticalblockonce=false, cs.pszFile=NULL, cs.nLine=0) From f85c0974492d9c779d45112fc943f0dbe0b95cda Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Fri, 24 Jun 2011 20:03:16 +0200 Subject: [PATCH 3/7] fix warnings: using the result of an assignment as a condition without parentheses [-Wparentheses] Don't unnecessarily assign to variables within the *boolean* expression of a conditional. Signed-off-by: Giel van Schijndel --- src/util.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/util.cpp b/src/util.cpp index 479c601ee..7693aaa52 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -760,8 +760,8 @@ string GetPidFile() void CreatePidFile(string pidFile, pid_t pid) { - FILE* file; - if (file = fopen(pidFile.c_str(), "w")) + FILE* file = fopen(pidFile.c_str(), "w"); + if (file) { fprintf(file, "%d\n", pid); fclose(file); @@ -790,7 +790,9 @@ void ShrinkDebugFile() fseek(file, -sizeof(pch), SEEK_END); int nBytes = fread(pch, 1, sizeof(pch), file); fclose(file); - if (file = fopen(strFile.c_str(), "w")) + + file = fopen(strFile.c_str(), "w"); + if (file) { fwrite(pch, 1, nBytes, file); fclose(file); From d7f1d200ab5d385c727261621c069dfbc6170e78 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Fri, 24 Jun 2011 20:09:24 +0200 Subject: [PATCH 4/7] fix warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare] Don't check for a negative parameter count, because not only will it never happen, it doesn't make any sense either. Invalid sockets (as returned by socket(2)) are always exactly -1 (not just negative as negative file descriptors are technically not prohibited by POSIX) on POSIX systems. Since we store them in SOCKET (unsigned int), however, that really is ~0U (or MAX_UINT) which happens to be what INVALID_SOCKET is already defined to, so an additional check for being negative is not only unnecessary (unsigned integers aren't *ever* negative) its redundant as well (the INVALID_SOCKET comparison is enough). Signed-off-by: Giel van Schijndel --- src/net.cpp | 2 +- src/rpc.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 0d3348da7..da1387449 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -831,7 +831,7 @@ void ThreadSocketHandler2(void* parg) { BOOST_FOREACH(CNode* pnode, vNodes) { - if (pnode->hSocket == INVALID_SOCKET || pnode->hSocket < 0) + if (pnode->hSocket == INVALID_SOCKET) continue; FD_SET(pnode->hSocket, &fdsetRecv); FD_SET(pnode->hSocket, &fdsetError); diff --git a/src/rpc.cpp b/src/rpc.cpp index fbed626a8..e71c5bcb4 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -706,7 +706,7 @@ int64 GetAccountBalance(const string& strAccount, int nMinDepth) Value getbalance(const Array& params, bool fHelp) { - if (fHelp || params.size() < 0 || params.size() > 2) + if (fHelp || params.size() > 2) throw runtime_error( "getbalance [account] [minconf=1]\n" "If [account] is not specified, returns the server's total available balance.\n" From 225f222c9fba7a831e2e5f80ccbba34ed2bca532 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Fri, 24 Jun 2011 20:47:26 +0200 Subject: [PATCH 5/7] fix warning: X enumeration values not handled in switch [-Wswitch-enum] Add default cases to opcode switches to assert that they should never occur. Signed-off-by: Giel van Schijndel --- src/script.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/script.cpp b/src/script.cpp index aa7f1f511..654aaa10e 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -580,6 +580,7 @@ bool EvalScript(vector >& stack, const CScript& script, co case OP_ABS: if (bn < bnZero) bn = -bn; break; case OP_NOT: bn = (bn == bnZero); break; case OP_0NOTEQUAL: bn = (bn != bnZero); break; + default: assert(!"invalid opcode"); break; } popstack(stack); stack.push_back(bn.getvch()); @@ -659,6 +660,7 @@ bool EvalScript(vector >& stack, const CScript& script, co case OP_GREATERTHANOREQUAL: bn = (bn1 >= bn2); break; case OP_MIN: bn = (bn1 < bn2 ? bn1 : bn2); break; case OP_MAX: bn = (bn1 > bn2 ? bn1 : bn2); break; + default: assert(!"invalid opcode"); break; } popstack(stack); popstack(stack); From 858cebed7dee2e9801e754a9969844b7969254ee Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Fri, 24 Jun 2011 22:00:59 +0200 Subject: [PATCH 6/7] fix warning: unused variable 'X' [-Wunused-variable] Remove several unused variables. Signed-off-by: Giel van Schijndel --- src/db.cpp | 2 -- src/net.cpp | 2 +- src/rpc.cpp | 1 - src/wallet.cpp | 3 --- 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/db.cpp b/src/db.cpp index 1dea92ead..4df05d68e 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -627,8 +627,6 @@ int64 CWalletDB::GetAccountCreditDebit(const string& strAccount) void CWalletDB::ListAccountCreditDebit(const string& strAccount, list& entries) { - int64 nCreditDebit = 0; - bool fAllAccounts = (strAccount == "*"); Dbc* pcursor = GetCursor(); diff --git a/src/net.cpp b/src/net.cpp index da1387449..ac5a2834b 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1700,7 +1700,7 @@ void StartNode(void* parg) printf("Error: CreateThread(ThreadIRCSeed) failed\n"); // Send and receive from sockets, accept connections - pthread_t hThreadSocketHandler = CreateThread(ThreadSocketHandler, NULL, true); + CreateThread(ThreadSocketHandler, NULL, true); // Initiate outbound connections if (!CreateThread(ThreadOpenConnections, NULL)) diff --git a/src/rpc.cpp b/src/rpc.cpp index e71c5bcb4..4016d265c 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -2419,7 +2419,6 @@ int CommandLineRPC(int argc, char *argv[]) // Parse reply const Value& result = find_value(reply, "result"); const Value& error = find_value(reply, "error"); - const Value& id = find_value(reply, "id"); if (error.type() != null_type) { diff --git a/src/wallet.cpp b/src/wallet.cpp index a211fde46..f4df5ecf6 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -722,8 +722,6 @@ void CWallet::ResendWalletTransactions() int64 CWallet::GetBalance() const { - int64 nStart = GetTimeMillis(); - int64 nTotal = 0; CRITICAL_BLOCK(cs_mapWallet) { @@ -736,7 +734,6 @@ int64 CWallet::GetBalance() const } } - //printf("GetBalance() %"PRI64d"ms\n", GetTimeMillis() - nStart); return nTotal; } From d0538a81bb7836865086d72ccc6a4d263fa49aef Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Fri, 24 Jun 2011 22:14:15 +0200 Subject: [PATCH 7/7] fix warning: unused function 'SigIllHandlerSSE2' [-Wunused-function] Only declare & define SigIllHandlerSSE2 when its used. Signed-off-by: Giel van Schijndel --- src/cryptopp/cpu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cryptopp/cpu.cpp b/src/cryptopp/cpu.cpp index 3e4680421..8789dc317 100644 --- a/src/cryptopp/cpu.cpp +++ b/src/cryptopp/cpu.cpp @@ -80,7 +80,7 @@ bool CpuId(word32 input, word32 *output) #endif } -#ifndef _MSC_VER +#if !CRYPTOPP_BOOL_X64 && !defined(_MSC_VER) && defined(__GNUC__) static jmp_buf s_jmpNoSSE2; static void SigIllHandlerSSE2(int) {