diff --git a/src/addrman.cpp b/src/addrman.cpp --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -554,7 +554,9 @@ void CAddrMan::GetAddr_(std::vector &vAddr) { unsigned int nNodes = ADDRMAN_GETADDR_MAX_PCT * vRandom.size() / 100; - if (nNodes > ADDRMAN_GETADDR_MAX) nNodes = ADDRMAN_GETADDR_MAX; + if (nNodes > ADDRMAN_GETADDR_MAX) { + nNodes = ADDRMAN_GETADDR_MAX; + } // gather a list of random nodes, skipping those of low quality for (unsigned int n = 0; n < vRandom.size(); n++) { diff --git a/src/arith_uint256.cpp b/src/arith_uint256.cpp --- a/src/arith_uint256.cpp +++ b/src/arith_uint256.cpp @@ -23,14 +23,18 @@ template base_uint &base_uint::operator<<=(unsigned int shift) { base_uint a(*this); - for (int i = 0; i < WIDTH; i++) + for (int i = 0; i < WIDTH; i++) { pn[i] = 0; + } int k = shift / 32; shift = shift % 32; for (int i = 0; i < WIDTH; i++) { - if (i + k + 1 < WIDTH && shift != 0) + if (i + k + 1 < WIDTH && shift != 0) { pn[i + k + 1] |= (a.pn[i] >> (32 - shift)); - if (i + k < WIDTH) pn[i + k] |= (a.pn[i] << shift); + } + if (i + k < WIDTH) { + pn[i + k] |= (a.pn[i] << shift); + } } return *this; } @@ -38,14 +42,18 @@ template base_uint &base_uint::operator>>=(unsigned int shift) { base_uint a(*this); - for (int i = 0; i < WIDTH; i++) + for (int i = 0; i < WIDTH; i++) { pn[i] = 0; + } int k = shift / 32; shift = shift % 32; for (int i = 0; i < WIDTH; i++) { - if (i - k - 1 >= 0 && shift != 0) + if (i - k - 1 >= 0 && shift != 0) { pn[i - k - 1] |= (a.pn[i] << (32 - shift)); - if (i - k >= 0) pn[i - k] |= (a.pn[i] >> shift); + } + if (i - k >= 0) { + pn[i - k] |= (a.pn[i] >> shift); + } } return *this; } @@ -86,9 +94,13 @@ *this = 0; int num_bits = num.bits(); int div_bits = div.bits(); - if (div_bits == 0) throw uint_error("Division by zero"); + if (div_bits == 0) { + throw uint_error("Division by zero"); + } // the result is certainly 0. - if (div_bits > num_bits) return *this; + if (div_bits > num_bits) { + return *this; + } int shift = num_bits - div_bits; // shift so that div and num align. div <<= shift; @@ -109,18 +121,28 @@ template int base_uint::CompareTo(const base_uint &b) const { for (int i = WIDTH - 1; i >= 0; i--) { - if (pn[i] < b.pn[i]) return -1; - if (pn[i] > b.pn[i]) return 1; + if (pn[i] < b.pn[i]) { + return -1; + } + if (pn[i] > b.pn[i]) { + return 1; + } } return 0; } template bool base_uint::EqualTo(uint64_t b) const { for (int i = WIDTH - 1; i >= 2; i--) { - if (pn[i]) return false; + if (pn[i]) { + return false; + } + } + if (pn[1] != (b >> 32)) { + return false; + } + if (pn[0] != (b & 0xfffffffful)) { + return false; } - if (pn[1] != (b >> 32)) return false; - if (pn[0] != (b & 0xfffffffful)) return false; return true; } @@ -194,11 +216,14 @@ *this = nWord; *this <<= 8 * (nSize - 3); } - if (pfNegative) *pfNegative = nWord != 0 && (nCompact & 0x00800000) != 0; - if (pfOverflow) + if (pfNegative) { + *pfNegative = nWord != 0 && (nCompact & 0x00800000) != 0; + } + if (pfOverflow) { *pfOverflow = nWord != 0 && ((nSize > 34) || (nWord > 0xff && nSize > 33) || (nWord > 0xffff && nSize > 32)); + } return *this; } @@ -227,13 +252,15 @@ uint256 ArithToUint256(const arith_uint256 &a) { uint256 b; - for (int x = 0; x < a.WIDTH; ++x) + for (int x = 0; x < a.WIDTH; ++x) { WriteLE32(b.begin() + x * 4, a.pn[x]); + } return b; } arith_uint256 UintToArith256(const uint256 &a) { arith_uint256 b; - for (int x = 0; x < b.WIDTH; ++x) + for (int x = 0; x < b.WIDTH; ++x) { b.pn[x] = ReadLE32(a.begin() + x * 4); + } return b; } diff --git a/src/base58.cpp b/src/base58.cpp --- a/src/base58.cpp +++ b/src/base58.cpp @@ -79,8 +79,9 @@ } // Skip leading zeroes in b256. std::vector::iterator it = b256.begin() + (size - length); - while (it != b256.end() && *it == 0) + while (it != b256.end() && *it == 0) { it++; + } // Copy result into output vector. vch.reserve(zeroes + (b256.end() - it)); vch.assign(zeroes, 0x00); diff --git a/src/clientversion.cpp b/src/clientversion.cpp --- a/src/clientversion.cpp +++ b/src/clientversion.cpp @@ -81,13 +81,14 @@ const std::string CLIENT_BUILD(BUILD_DESC CLIENT_VERSION_SUFFIX); static std::string FormatVersion(int nVersion) { - if (nVersion % 100 == 0) + if (nVersion % 100 == 0) { return strprintf("%d.%d.%d", nVersion / 1000000, (nVersion / 10000) % 100, (nVersion / 100) % 100); - else + } else { return strprintf("%d.%d.%d.%d", nVersion / 1000000, (nVersion / 10000) % 100, (nVersion / 100) % 100, nVersion % 100); + } } std::string FormatFullVersion() { @@ -106,8 +107,9 @@ if (!comments.empty()) { std::vector::const_iterator it(comments.begin()); ss << "(" << *it; - for (++it; it != comments.end(); ++it) + for (++it; it != comments.end(); ++it) { ss << "; " << *it; + } ss << ")"; } ss << "/"; diff --git a/src/compat/glibc_sanity.cpp b/src/compat/glibc_sanity.cpp --- a/src/compat/glibc_sanity.cpp +++ b/src/compat/glibc_sanity.cpp @@ -26,13 +26,16 @@ template bool sanity_test_memcpy() { unsigned int memcpy_test[T]; unsigned int memcpy_verify[T] = {}; - for (unsigned int i = 0; i != T; ++i) + for (unsigned int i = 0; i != T; ++i) { memcpy_test[i] = i; + } memcpy_int(memcpy_verify, memcpy_test, sizeof(memcpy_test)); for (unsigned int i = 0; i != T; ++i) { - if (memcpy_verify[i] != i) return false; + if (memcpy_verify[i] != i) { + return false; + } } return true; } @@ -54,7 +57,9 @@ bool glibc_sanity_test() { #if defined(HAVE_SYS_SELECT_H) - if (!sanity_test_fdelt()) return false; + if (!sanity_test_fdelt()) { + return false; + } #endif return sanity_test_memcpy<1025>(); } diff --git a/src/compat/glibcxx_sanity.cpp b/src/compat/glibcxx_sanity.cpp --- a/src/compat/glibcxx_sanity.cpp +++ b/src/compat/glibcxx_sanity.cpp @@ -22,13 +22,18 @@ // they match the original sequence. bool sanity_test_list(unsigned int size) { std::list test; - for (unsigned int i = 0; i != size; ++i) + for (unsigned int i = 0; i != size; ++i) { test.push_back(i + 1); + } - if (test.size() != size) return false; + if (test.size() != size) { + return false; + } while (!test.empty()) { - if (test.back() != test.size()) return false; + if (test.back() != test.size()) { + return false; + } test.pop_back(); } return true; diff --git a/src/compressor.cpp b/src/compressor.cpp --- a/src/compressor.cpp +++ b/src/compressor.cpp @@ -124,7 +124,9 @@ vch[0] = nSize - 2; memcpy(&vch[1], in.data(), 32); CPubKey pubkey(&vch[0], &vch[33]); - if (!pubkey.Decompress()) return false; + if (!pubkey.Decompress()) { + return false; + } assert(pubkey.size() == 65); script.resize(67); script[0] = 65; diff --git a/src/consensus/merkle.cpp b/src/consensus/merkle.cpp --- a/src/consensus/merkle.cpp +++ b/src/consensus/merkle.cpp @@ -47,7 +47,9 @@ while (hashes.size() > 1) { if (mutated) { for (size_t pos = 0; pos + 1 < hashes.size(); pos += 2) { - if (hashes[pos] == hashes[pos + 1]) mutation = true; + if (hashes[pos] == hashes[pos + 1]) { + mutation = true; + } } } if (hashes.size() & 1) { @@ -56,8 +58,12 @@ SHA256D64(hashes[0].begin(), hashes[0].begin(), hashes.size() / 2); hashes.resize(hashes.size() / 2); } - if (mutated) *mutated = mutation; - if (hashes.size() == 0) return uint256(); + if (mutated) { + *mutated = mutation; + } + if (hashes.size() == 0) { + return uint256(); + } return hashes[0]; } diff --git a/src/httprpc.cpp b/src/httprpc.cpp --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -72,10 +72,11 @@ int nStatus = HTTP_INTERNAL_SERVER_ERROR; int code = find_value(objError, "code").get_int(); - if (code == RPC_INVALID_REQUEST) + if (code == RPC_INVALID_REQUEST) { nStatus = HTTP_BAD_REQUEST; - else if (code == RPC_METHOD_NOT_FOUND) + } else if (code == RPC_METHOD_NOT_FOUND) { nStatus = HTTP_NOT_FOUND; + } std::string strReply = JSONRPCReply(NullUniValue, objError, id); @@ -316,8 +317,9 @@ try { // Parse request UniValue valRequest; - if (!valRequest.read(req->ReadBody())) + if (!valRequest.read(req->ReadBody())) { throw JSONRPCError(RPC_PARSE_ERROR, "Parse error"); + } // Set the URI jreq.URI = req->GetURI(); diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -1957,9 +1957,10 @@ // sanitize comments per BIP-0014, format user agent and check total size std::vector uacomments; for (const std::string &cmt : gArgs.GetArgs("-uacomment")) { - if (cmt != SanitizeString(cmt, SAFE_CHARS_UA_COMMENT)) + if (cmt != SanitizeString(cmt, SAFE_CHARS_UA_COMMENT)) { return InitError(strprintf( _("User Agent comment (%s) contains unsafe characters."), cmt)); + } uacomments.push_back(cmt); } const std::string strSubVersion = diff --git a/src/net.cpp b/src/net.cpp --- a/src/net.cpp +++ b/src/net.cpp @@ -321,8 +321,9 @@ LOCK(cs_vNodes); for (const CNode *pnode : vNodes) { if (!pnode->fSuccessfullyConnected && !pnode->fInbound && - pnode->GetLocalNonce() == nonce) + pnode->GetLocalNonce() == nonce) { return false; + } } return true; } diff --git a/src/noui.cpp b/src/noui.cpp --- a/src/noui.cpp +++ b/src/noui.cpp @@ -42,7 +42,9 @@ strCaption += caption; } - if (!fSecure) LogPrintf("%s: %s\n", strCaption, message); + if (!fSecure) { + LogPrintf("%s: %s\n", strCaption, message); + } fprintf(stderr, "%s: %s\n", strCaption.c_str(), message.c_str()); return false; } diff --git a/src/pow.cpp b/src/pow.cpp --- a/src/pow.cpp +++ b/src/pow.cpp @@ -83,7 +83,9 @@ // Make sure we do not go below allowed values. const arith_uint256 bnPowLimit = UintToArith256(params.powLimit); - if (nPow > bnPowLimit) nPow = bnPowLimit; + if (nPow > bnPowLimit) { + nPow = bnPowLimit; + } return nPow.GetCompact(); } diff --git a/src/qt/intro.cpp b/src/qt/intro.cpp --- a/src/qt/intro.cpp +++ b/src/qt/intro.cpp @@ -86,7 +86,9 @@ /* Check if we make any progress, break if not to prevent an infinite * loop here */ - if (parentDirOld == parentDir) break; + if (parentDirOld == parentDir) { + break; + } parentDirOld = parentDir; } @@ -186,7 +188,9 @@ QSettings settings; /* If data directory provided on command line, no need to look at settings or show a picking dialog */ - if (!gArgs.GetArg("-datadir", "").empty()) return true; + if (!gArgs.GetArg("-datadir", "").empty()) { + return true; + } /* 1) Default data directory for operating system */ QString dataDir = getDefaultDataDirectory(); /* 2) Allow QSettings to override default dir */ @@ -282,7 +286,9 @@ void Intro::on_ellipsisButton_clicked() { QString dir = QDir::toNativeSeparators(QFileDialog::getExistingDirectory( 0, "Choose data directory", ui->dataDirectory->text())); - if (!dir.isEmpty()) ui->dataDirectory->setText(dir); + if (!dir.isEmpty()) { + ui->dataDirectory->setText(dir); + } } void Intro::on_dataDirDefault_clicked() { diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -197,8 +197,9 @@ UniValue ParseNonRFCJSONValue(const std::string &strVal) { UniValue jVal; if (!jVal.read(std::string("[") + strVal + std::string("]")) || - !jVal.isArray() || jVal.size() != 1) + !jVal.isArray() || jVal.size() != 1) { throw std::runtime_error(std::string("Error parsing JSON:") + strVal); + } return jVal[0]; } diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -831,6 +831,7 @@ // clang-format on void RegisterMiningRPCCommands(CRPCTable &t) { - for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) + for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) { t.appendCommand(commands[vcidx].name, &commands[vcidx]); + } } diff --git a/src/timedata.cpp b/src/timedata.cpp --- a/src/timedata.cpp +++ b/src/timedata.cpp @@ -45,8 +45,12 @@ LOCK(cs_nTimeOffset); // Ignore duplicates static std::set setKnown; - if (setKnown.size() == BITCOIN_TIMEDATA_MAX_SAMPLES) return; - if (!setKnown.insert(ip).second) return; + if (setKnown.size() == BITCOIN_TIMEDATA_MAX_SAMPLES) { + return; + } + if (!setKnown.insert(ip).second) { + return; + } // Add data static CMedianFilter vTimeOffsets(BITCOIN_TIMEDATA_MAX_SAMPLES, 0); @@ -89,7 +93,9 @@ // of ours, give a warning bool fMatch = false; for (const int64_t nOffset : vSorted) { - if (nOffset != 0 && abs64(nOffset) < 5 * 60) fMatch = true; + if (nOffset != 0 && abs64(nOffset) < 5 * 60) { + fMatch = true; + } } if (!fMatch) { diff --git a/src/util/strencodings.cpp b/src/util/strencodings.cpp --- a/src/util/strencodings.cpp +++ b/src/util/strencodings.cpp @@ -414,7 +414,8 @@ } } - if (pfInvalid) switch (mode) { + if (pfInvalid) { + switch (mode) { case 0: // 8n base32 characters processed: ok break; @@ -453,6 +454,7 @@ } break; } + } return vchRet; } @@ -849,7 +851,9 @@ } std::string Capitalize(std::string str) { - if (str.empty()) return str; + if (str.empty()) { + return str; + } str[0] = ToUpper(str.front()); return str; } diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -742,7 +742,7 @@ } Dbc *pcursor = db.GetCursor(); - if (pcursor) + if (pcursor) { while (fSuccess) { CDataStream ssKey(SER_DISK, CLIENT_VERSION); CDataStream ssValue(SER_DISK, CLIENT_VERSION); @@ -775,6 +775,7 @@ fSuccess = false; } } + } if (fSuccess) { db.Close(); env->CloseDb(strFile); diff --git a/src/zmq/zmqnotificationinterface.cpp b/src/zmq/zmqnotificationinterface.cpp --- a/src/zmq/zmqnotificationinterface.cpp +++ b/src/zmq/zmqnotificationinterface.cpp @@ -127,7 +127,9 @@ const CBlockIndex *pindexFork, bool fInitialDownload) { // In IBD or blocks were disconnected without any new ones - if (fInitialDownload || pindexNew == pindexFork) return; + if (fInitialDownload || pindexNew == pindexFork) { + return; + } for (std::list::iterator i = notifiers.begin(); i != notifiers.end();) {