From 2b85d31bcc2f6985428f9cf731329af15d5c8b25 Mon Sep 17 00:00:00 2001 From: fanquake Date: Tue, 18 Mar 2025 08:04:23 +0800 Subject: [PATCH 1/2] refactor: starts/ends_with changes for clang-tidy 20 --- src/bitcoin-cli.cpp | 2 +- src/common/args.cpp | 4 ++-- src/common/config.cpp | 2 +- src/core_read.cpp | 2 +- src/httprpc.cpp | 2 +- src/i2p.cpp | 2 +- src/node/blockstorage.cpp | 6 +++--- src/qt/test/rpcnestedtests.cpp | 6 +++--- src/util/string.h | 2 +- src/wallet/rpc/backup.cpp | 2 +- src/zmq/zmqnotificationinterface.cpp | 2 +- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 79410b73035..03104b81361 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -1220,7 +1220,7 @@ static int CommandLineRPC(int argc, char *argv[]) if (gArgs.GetBoolArg("-stdinwalletpassphrase", false)) { NO_STDIN_ECHO(); std::string walletPass; - if (args.size() < 1 || args[0].substr(0, 16) != "walletpassphrase") { + if (args.size() < 1 || !args[0].starts_with("walletpassphrase")) { throw std::runtime_error("-stdinwalletpassphrase is only applicable for walletpassphrase(change)"); } if (!StdinReady()) { diff --git a/src/common/args.cpp b/src/common/args.cpp index 833a0b28bd2..1e3f6d1b88d 100644 --- a/src/common/args.cpp +++ b/src/common/args.cpp @@ -85,7 +85,7 @@ KeyInfo InterpretKey(std::string key) result.section = key.substr(0, option_index); key.erase(0, option_index + 1); } - if (key.substr(0, 2) == "no") { + if (key.starts_with("no")) { key.erase(0, 2); result.negated = true; } @@ -189,7 +189,7 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin // internet" warning, and clicks the Open button, macOS passes // a unique process serial number (PSN) as -psn_... command-line // argument, which we filter out. - if (key.substr(0, 5) == "-psn_") continue; + if (key.starts_with("-psn_")) continue; #endif if (key == "-") break; //bitcoin-tx using stdin diff --git a/src/common/config.cpp b/src/common/config.cpp index fac4aa314c5..42f5e283348 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -65,7 +65,7 @@ static bool GetConfigOptions(std::istream& stream, const std::string& filepath, } } else { error = strprintf("parse error on line %i: %s", linenr, str); - if (str.size() >= 2 && str.substr(0, 2) == "no") { + if (str.size() >= 2 && str.starts_with("no")) { error += strprintf(", if you intended to specify a negated option, use %s=1 instead", str); } return false; diff --git a/src/core_read.cpp b/src/core_read.cpp index 273dfb17e86..27d0d9d7403 100644 --- a/src/core_read.cpp +++ b/src/core_read.cpp @@ -83,7 +83,7 @@ CScript ParseScript(const std::string& s) } result << num.value(); - } else if (w.substr(0, 2) == "0x" && w.size() > 2 && IsHex(std::string(w.begin() + 2, w.end()))) { + } else if (w.starts_with("0x") && w.size() > 2 && IsHex(std::string(w.begin() + 2, w.end()))) { // Raw hex data, inserted NOT pushed onto stack: std::vector raw = ParseHex(std::string(w.begin() + 2, w.end())); result.insert(result.end(), raw.begin(), raw.end()); diff --git a/src/httprpc.cpp b/src/httprpc.cpp index 57893702b8b..6d2dffaf7a1 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -134,7 +134,7 @@ static bool multiUserAuthorized(std::string strUserPass) static bool RPCAuthorized(const std::string& strAuth, std::string& strAuthUsernameOut) { - if (strAuth.substr(0, 6) != "Basic ") + if (!strAuth.starts_with("Basic ")) return false; std::string_view strUserPass64 = TrimStringView(std::string_view{strAuth}.substr(6)); auto userpass_data = DecodeBase64(strUserPass64); diff --git a/src/i2p.cpp b/src/i2p.cpp index 156c8024339..8b48615afeb 100644 --- a/src/i2p.cpp +++ b/src/i2p.cpp @@ -299,7 +299,7 @@ Session::Reply Session::SendRequestAndGetReply(const Sock& sock, Reply reply; // Don't log the full "SESSION CREATE ..." because it contains our private key. - reply.request = request.substr(0, 14) == "SESSION CREATE" ? "SESSION CREATE ..." : request; + reply.request = request.starts_with("SESSION CREATE") ? "SESSION CREATE ..." : request; // It could take a few minutes for the I2P router to reply as it is querying the I2P network // (when doing name lookup, for example). Notice: `RecvUntilTerminator()` is checking diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index 3d73459bf6c..f8cdd4ce08c 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -624,11 +624,11 @@ void BlockManager::CleanupBlockRevFiles() const const std::string path = fs::PathToString(it->path().filename()); if (fs::is_regular_file(*it) && path.length() == 12 && - path.substr(8,4) == ".dat") + path.ends_with(".dat")) { - if (path.substr(0, 3) == "blk") { + if (path.starts_with("blk")) { mapBlockFiles[path.substr(3, 5)] = it->path(); - } else if (path.substr(0, 3) == "rev") { + } else if (path.starts_with("rev")) { remove(it->path()); } } diff --git a/src/qt/test/rpcnestedtests.cpp b/src/qt/test/rpcnestedtests.cpp index 0797d31a71a..eb74ef8559d 100644 --- a/src/qt/test/rpcnestedtests.cpp +++ b/src/qt/test/rpcnestedtests.cpp @@ -64,13 +64,13 @@ void RPCNestedTests::rpcNestedTests() RPCConsole::RPCExecuteCommandLine(m_node, result, "getblock( getblock( getblock(getbestblockhash())[hash] )[hash], true)"); //4 level nesting with whitespace, filtering path and boolean parameter RPCConsole::RPCExecuteCommandLine(m_node, result, "getblockchaininfo"); - QVERIFY(result.substr(0,1) == "{"); + QVERIFY(result.starts_with("{")); RPCConsole::RPCExecuteCommandLine(m_node, result, "getblockchaininfo()"); - QVERIFY(result.substr(0,1) == "{"); + QVERIFY(result.starts_with("{")); RPCConsole::RPCExecuteCommandLine(m_node, result, "getblockchaininfo "); //whitespace at the end will be tolerated - QVERIFY(result.substr(0,1) == "{"); + QVERIFY(result.starts_with("{")); RPCConsole::RPCExecuteCommandLine(m_node, result, "getblockchaininfo()[\"chain\"]"); //Quote path identifier are allowed, but look after a child containing the quotes in the key QVERIFY(result == "null"); diff --git a/src/util/string.h b/src/util/string.h index 3075e46abbf..4b875256275 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -168,7 +168,7 @@ std::vector Split(const std::span& sp, char sep) [[nodiscard]] inline std::string_view RemovePrefixView(std::string_view str, std::string_view prefix) { - if (str.substr(0, prefix.size()) == prefix) { + if (str.starts_with(prefix)) { return str.substr(prefix.size()); } return str; diff --git a/src/wallet/rpc/backup.cpp b/src/wallet/rpc/backup.cpp index e12453458c4..291c3bb9430 100644 --- a/src/wallet/rpc/backup.cpp +++ b/src/wallet/rpc/backup.cpp @@ -559,7 +559,7 @@ RPCHelpMan importwallet() fLabel = false; if (vstr[nStr] == "reserve=1") fLabel = false; - if (vstr[nStr].substr(0,6) == "label=") { + if (vstr[nStr].starts_with("label=")) { strLabel = DecodeDumpString(vstr[nStr].substr(6)); fLabel = true; } diff --git a/src/zmq/zmqnotificationinterface.cpp b/src/zmq/zmqnotificationinterface.cpp index 0039f556981..4f01e8fd330 100644 --- a/src/zmq/zmqnotificationinterface.cpp +++ b/src/zmq/zmqnotificationinterface.cpp @@ -58,7 +58,7 @@ std::unique_ptr CZMQNotificationInterface::Create(std const auto& factory = entry.second; for (std::string& address : gArgs.GetArgs(arg)) { // libzmq uses prefix "ipc://" for UNIX domain sockets - if (address.substr(0, ADDR_PREFIX_UNIX.length()) == ADDR_PREFIX_UNIX) { + if (address.starts_with(ADDR_PREFIX_UNIX)) { address.replace(0, ADDR_PREFIX_UNIX.length(), ADDR_PREFIX_IPC); } From 08aa7fe2326391e6d633c2da50959754e3e7b8d6 Mon Sep 17 00:00:00 2001 From: fanquake Date: Thu, 17 Apr 2025 17:09:42 +0100 Subject: [PATCH 2/2] ci: clang-tidy 20 --- ci/test/00_setup_env_native_tidy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/test/00_setup_env_native_tidy.sh b/ci/test/00_setup_env_native_tidy.sh index 08a7cbbf7e4..0a593a21820 100755 --- a/ci/test/00_setup_env_native_tidy.sh +++ b/ci/test/00_setup_env_native_tidy.sh @@ -8,7 +8,7 @@ export LC_ALL=C.UTF-8 export CI_IMAGE_NAME_TAG="mirror.gcr.io/ubuntu:24.04" export CONTAINER_NAME=ci_native_tidy -export TIDY_LLVM_V="19" +export TIDY_LLVM_V="20" export APT_LLVM_V="${TIDY_LLVM_V}" export PACKAGES="clang-${TIDY_LLVM_V} libclang-${TIDY_LLVM_V}-dev llvm-${TIDY_LLVM_V}-dev libomp-${TIDY_LLVM_V}-dev clang-tidy-${TIDY_LLVM_V} jq libevent-dev libboost-dev libzmq3-dev systemtap-sdt-dev qt6-base-dev qt6-tools-dev qt6-l10n-tools libqrencode-dev libsqlite3-dev libdb++-dev" export NO_DEPENDS=1