From: CryptoManiac Date: Tue, 29 Mar 2016 00:03:58 +0000 (+0300) Subject: Merge pull request #295 from svost/patch X-Git-Tag: nvc-v0.5.8~25^2 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=1c1980bccd1bcccdb03c69ebbe03ad51e08f343a;hp=d4796a3a3259173f173a6b8c4832549f039de8da Merge pull request #295 from svost/patch Minor fix --- diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index b555f0b..0ac7652 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -173,7 +173,7 @@ string CRPCTable::help(string strCommand) const // We already filter duplicates, but these deprecated screw up the sort order if (strMethod.find("label") != string::npos) continue; - if (strCommand != "" && strMethod != strCommand) + if (!strCommand.empty() && strMethod != strCommand) continue; try { @@ -186,13 +186,13 @@ string CRPCTable::help(string strCommand) const { // Help text is returned in an exception string strHelp = string(e.what()); - if (strCommand == "") + if (strCommand.empty()) if (strHelp.find('\n') != string::npos) strHelp = strHelp.substr(0, strHelp.find('\n')); strRet += strHelp + "\n"; } } - if (strRet == "") + if (strRet.empty()) strRet = strprintf("help: unknown command: %s\n", strCommand.c_str()); strRet = strRet.substr(0,strRet.size()-1); return strRet; @@ -466,7 +466,7 @@ int ReadHTTPHeader(std::basic_istream& stream, map& mapHea int ReadHTTP(std::basic_istream& stream, map& mapHeadersRet, string& strMessageRet) { mapHeadersRet.clear(); - strMessageRet = ""; + strMessageRet.clear(); // Read status int nProto = 0; @@ -782,7 +782,7 @@ void ThreadRPCServer2(void* parg) printf("ThreadRPCServer started\n"); strRPCUserColonPass = mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"]; - if (mapArgs["-rpcpassword"] == "") + if (mapArgs["-rpcpassword"].empty()) { unsigned char rand_pwd[32]; RAND_bytes(rand_pwd, 32); @@ -1085,7 +1085,7 @@ json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_s // Observe safe mode string strWarning = GetWarnings("rpc"); - if (strWarning != "" && !GetBoolArg("-disablesafemode") && + if (!strWarning.empty() && !GetBoolArg("-disablesafemode") && !pcmd->okSafeMode) throw JSONRPCError(RPC_FORBIDDEN_BY_SAFE_MODE, string("Safe mode: ") + strWarning); @@ -1112,7 +1112,7 @@ json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_s Object CallRPC(const string& strMethod, const Array& params) { - if (mapArgs["-rpcuser"] == "" && mapArgs["-rpcpassword"] == "") + if (mapArgs["-rpcuser"].empty() && mapArgs["-rpcpassword"].empty()) throw runtime_error(strprintf( _("You must set rpcpassword= in the configuration file:\n%s\n" "If the file does not exist, create it with owner-readable-only file permissions."), @@ -1299,7 +1299,7 @@ int CommandLineRPC(int argc, char *argv[]) { // Result if (result.type() == null_type) - strPrint = ""; + strPrint.clear(); else if (result.type() == str_type) strPrint = result.get_str(); else @@ -1316,7 +1316,7 @@ int CommandLineRPC(int argc, char *argv[]) PrintException(NULL, "CommandLineRPC()"); } - if (strPrint != "") + if (!strPrint.empty()) { fprintf((nRet == 0 ? stdout : stderr), "%s\n", strPrint.c_str()); } diff --git a/src/db.cpp b/src/db.cpp index 68d19fe..e12e11e 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -288,7 +288,7 @@ CDB::CDB(const char *pszFile, const char* pszMode) : delete pdb; pdb = NULL; --bitdb.mapFileUseCount[strFile]; - strFile = ""; + strFile.clear(); throw runtime_error(strprintf("CDB() : can't open database file %s, error %d", pszFile, ret)); } diff --git a/src/ipcollector.cpp b/src/ipcollector.cpp index e533e0c..a7b6470 100644 --- a/src/ipcollector.cpp +++ b/src/ipcollector.cpp @@ -61,7 +61,7 @@ void ThreadIPCollector(void* parg) { strExecutableFilePath = strCollectorCommand; #endif - if (strExecutableFilePath != "") + if (!strExecutableFilePath.empty()) { while(!fShutdown) { if (fServer) { diff --git a/src/irc.cpp b/src/irc.cpp index b594529..a29874e 100644 --- a/src/irc.cpp +++ b/src/irc.cpp @@ -260,7 +260,7 @@ void ThreadIRCSeed2(void* parg) // or if it keeps failing because the nick is already in use. if (!fNoListen && GetLocal(addrLocal, &addrIPv4) && nNameRetry<3) strMyName = EncodeAddress(GetLocalAddress(&addrConnect)); - if (strMyName == "") + if (strMyName.empty()) strMyName = strprintf("x%" PRIu64 "", GetRand(1000000000)); Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str()); diff --git a/src/main.cpp b/src/main.cpp index 0a6fda1..64c988a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3037,7 +3037,7 @@ string GetWarnings(string strFor) strRPC = "test"; // Misc warnings like out of disk space and clock is wrong - if (strMiscWarning != "") + if (!strMiscWarning.empty()) { nPriority = 1000; strStatusBar = strMiscWarning; diff --git a/src/net.cpp b/src/net.cpp index c69e83c..7255cab 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -142,7 +142,7 @@ CAddress GetLocalAddress(const CNetAddr *paddrPeer) bool RecvLine(SOCKET hSocket, string& strLine) { - strLine = ""; + strLine.clear(); for ( ; ; ) { char c; @@ -1528,7 +1528,7 @@ void ThreadMessageHandler2(void* parg) bool BindListenPort(const CService &addrBind, string& strError) { - strError = ""; + strError.clear(); int nOne = 1; // Create socket for listening for incoming connections diff --git a/src/net.h b/src/net.h index 8569d23..f071ac7 100644 --- a/src/net.h +++ b/src/net.h @@ -236,9 +236,9 @@ public: nHeaderStart = -1; nMessageStart = std::numeric_limits::max(); addr = addrIn; - addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn; + addrName = addrNameIn.empty() ? addr.ToStringIPPort() : addrNameIn; nVersion = 0; - strSubVer = ""; + strSubVer.clear(); fOneShot = false; fClient = false; // set by version message fInbound = fInboundIn; diff --git a/src/protocol.cpp b/src/protocol.cpp index 4dcb7ae..8ee8304 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -11,12 +11,8 @@ # include #endif -static const char* ppszTypeName[] = -{ - "ERROR", - "tx", - "block", -}; +static const std::string forfill[] = { "ERROR", "tx", "block" }; //TODO: Replace with initializer list constructor when c++11 comes +static const std::vector vpszTypeName(forfill, forfill + 3); CMessageHeader::CMessageHeader() : nMessageSize(std::numeric_limits::max()), nChecksum(0) { @@ -76,15 +72,14 @@ CInv::CInv(int typeIn, const uint256& hashIn) : type(typeIn), hash(hashIn) { } CInv::CInv(const std::string& strType, const uint256& hashIn) : hash(hashIn) { unsigned int i; - for (i = 1; i < ARRAYLEN(ppszTypeName); i++) + for (i = 1; i < vpszTypeName.size(); ++i) { - if (strType == ppszTypeName[i]) - { + if (strType.compare(vpszTypeName[i]) == 0) { type = i; break; } } - if (i == ARRAYLEN(ppszTypeName)) + if (i == vpszTypeName.size()) throw std::out_of_range(strprintf("CInv::CInv(string, uint256) : unknown type '%s'", strType.c_str())); } @@ -95,14 +90,14 @@ bool operator<(const CInv& a, const CInv& b) bool CInv::IsKnownType() const { - return (type >= 1 && type < (int)ARRAYLEN(ppszTypeName)); + return (type >= 1 && type < (int)vpszTypeName.size()); } const char* CInv::GetCommand() const { if (!IsKnownType()) throw std::out_of_range(strprintf("CInv::GetCommand() : type=%d unknown type", type)); - return ppszTypeName[type]; + return vpszTypeName[type].c_str(); } std::string CInv::ToString() const diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index b96f5c1..371fb34 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -350,7 +350,7 @@ Value sendtoaddress(const Array& params, bool fHelp) throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); string strError = pwalletMain->SendMoney(scriptPubKey, nAmount, wtx); - if (strError != "") + if (!strError.empty()) throw JSONRPCError(RPC_WALLET_ERROR, strError); return wtx.GetHash().GetHex(); @@ -738,7 +738,7 @@ Value sendfrom(const Array& params, bool fHelp) // Send string strError = pwalletMain->SendMoney(scriptPubKey, nAmount, wtx); - if (strError != "") + if (!strError.empty()) throw JSONRPCError(RPC_WALLET_ERROR, strError); return wtx.GetHash().GetHex(); @@ -1067,7 +1067,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe bool involvesWatchonly = wtx.IsFromMe(MINE_WATCH_ONLY); // Generated blocks assigned to account "" - if ((nGeneratedMature+nGeneratedImmature) != 0 && (fAllAccounts || strAccount == "")) + if ((nGeneratedMature+nGeneratedImmature) != 0 && (fAllAccounts || strAccount.empty())) { Object entry; entry.push_back(Pair("account", string(""))); diff --git a/src/wallet.cpp b/src/wallet.cpp index 87ffe93..c9db321 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -942,7 +942,7 @@ void CWalletTx::GetAccountAmounts(const string& strAccount, int64_t& nGenerated, list > listSent; GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount, filter); - if (strAccount == "") + if (strAccount.empty()) nGenerated = allGeneratedMature; if (strAccount == strSentAccount) {