From 3a1399850dc4e4368bacbac8affc2dd31182c368 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Tue, 27 Feb 2024 09:19:51 +0000 Subject: [PATCH] Upgrade to NDK r26c with its new clang-tidy build. --- app-linux/makefile | 2 ++ app-windows/source/main.cpp | 4 ++-- env/setup-ndk.sh | 2 +- env/target-and.mk | 5 ++--- env/target-elf.mk | 2 +- eth-sender/makefile | 7 +++++-- eth-sender/source/scan.cpp | 2 +- min-v8/target.mk | 6 ++++++ min-wireshark/target.mk | 3 +++ min-zlib/target.mk | 2 +- p2p/boost | 2 +- p2p/c-ares | 2 +- p2p/source/buffer.hpp | 6 ++++-- p2p/source/cache.hpp | 2 +- p2p/source/category.cpp | 16 +++++++++------- p2p/source/chain.cpp | 17 ++++++++++------- p2p/source/cipher.hpp | 4 ++-- p2p/source/crypto.cpp | 7 ++++--- p2p/source/datagram.cpp | 4 ++-- p2p/source/encoding.cpp | 4 ++-- p2p/source/error.hpp | 4 ++++ p2p/source/load.cpp | 35 +++++++++++++++++++++------------- p2p/source/load.hpp | 8 ++++---- p2p/source/local.cpp | 2 +- p2p/source/log.cpp | 4 ++-- p2p/source/nested.cpp | 2 +- p2p/source/remote.cpp | 32 ++++++++++++++++--------------- p2p/source/scope.hpp | 2 +- p2p/source/spawn.cpp | 6 +++--- p2p/source/store.cpp | 4 ++-- p2p/source/syscall.hpp | 5 ++++- p2p/source/threads.cpp | 2 +- p2p/source/time.cpp | 8 ++++---- p2p/source/trace.cpp | 2 +- p2p/source/transport.cpp | 9 +++++---- p2p/source/trezor.cpp | 10 ++++++---- p2p/source/valve.cpp | 6 +++--- srv-daemon/source/lottery0.hpp | 2 +- srv-daemon/source/lottery1.hpp | 2 +- srv-daemon/source/main.cpp | 8 ++++---- srv-daemon/source/node.cpp | 2 +- srv-kernel/source/main.cpp | 6 ++++-- srv-worker/source/main.cpp | 12 ++++++------ vpn-shared/source/capture.cpp | 10 ++++++---- vpn-windows/source/protect.cpp | 12 ++++++------ vpn-windows/source/tunnel.cpp | 4 ++-- 46 files changed, 172 insertions(+), 126 deletions(-) diff --git a/app-linux/makefile b/app-linux/makefile index cd0a91ccf..4c3e40e8d 100644 --- a/app-linux/makefile +++ b/app-linux/makefile @@ -32,6 +32,8 @@ source += $(wildcard $(pwd)/source/*.cpp) cflags/$(pwd)/source/main.cpp += -Wno-unused-function checks/$(pwd)/source/main.cpp += -clang-diagnostic-unused-function checks/$(pwd)/source/main.cpp += -cppcoreguidelines-pro-type-cstyle-cast +checks/$(pwd)/source/main.cpp += -misc-use-anonymous-namespace +checks/$(pwd)/source/main.cpp += -misc-const-correctness $(call include,shared/target-lnx.mk) diff --git a/app-windows/source/main.cpp b/app-windows/source/main.cpp index 69451430a..9c7738972 100644 --- a/app-windows/source/main.cpp +++ b/app-windows/source/main.cpp @@ -43,8 +43,8 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE hPrevInstance, project.set_dart_entrypoint_arguments(GetCommandLineArguments()); FlutterWindow window(project); - Win32Window::Point origin(10, 10); - Win32Window::Size size(360, 640); + const Win32Window::Point origin(10, 10); + const Win32Window::Size size(360, 640); if (!window.Create(L"orchid", origin, size)) return EXIT_FAILURE; window.SetQuitOnClose(true); diff --git a/env/setup-ndk.sh b/env/setup-ndk.sh index b89bfd8f4..70f571e7f 100755 --- a/env/setup-ndk.sh +++ b/env/setup-ndk.sh @@ -1,4 +1,4 @@ #!/bin/bash set -e set -o pipefail -echo y | "${ANDROID_HOME}"/cmdline-tools/latest/bin/sdkmanager "build-tools;29.0.2" "ndk;25.2.9519653" "platforms;android-33" >/dev/null +echo y | "${ANDROID_HOME}"/cmdline-tools/latest/bin/sdkmanager "build-tools;29.0.2" "ndk;26.2.11394342" "platforms;android-33" >/dev/null diff --git a/env/target-and.mk b/env/target-and.mk index 131bfbaac..8a00f5bcf 100644 --- a/env/target-and.mk +++ b/env/target-and.mk @@ -70,9 +70,6 @@ more = --sysroot=$(llvm)/sysroot more += -fno-addrsig include $(pwd)/kit-android.mk -cxx += -stdlib=libc++ -lflags += -static-libstdc++ - define _ temp := $(subst -,$(space),$(host/$(1))) arch := $$(word 1,$$(temp)) @@ -86,6 +83,8 @@ $(each) endif +include $(pwd)/target-cxx.mk + lflags += -lm -llog wflags += -L$(CURDIR)/env/android diff --git a/env/target-elf.mk b/env/target-elf.mk index f0ff8bd37..bb474ee15 100644 --- a/env/target-elf.mk +++ b/env/target-elf.mk @@ -10,7 +10,7 @@ include $(pwd)/target-lld.mk -lflags += -Wl,-error-limit=0 +#lflags += -Wl,-error-limit=0 lflags += -Wl,--build-id=none lflags += -Wl,-z,relro lflags += -Wl,--no-undefined diff --git a/eth-sender/makefile b/eth-sender/makefile index f659a798f..3fdb928dc 100644 --- a/eth-sender/makefile +++ b/eth-sender/makefile @@ -29,8 +29,11 @@ all: $(output)/$(machine)/cj$(exe) test: $(output)/$(machine)/cj$(exe) $< $(args) -source += $(wildcard source/*.cpp) -cflags += -Isource +source += $(wildcard $(pwd)/source/*.cpp) +cflags += -I$(pwd)/source + +# XXX: this literally crashes clang-tidy and I haven't filed the bug +checks/$(pwd)/source/main.cpp += -bugprone-unchecked-optional-access $(call include,p2p/target.mk) include env/output.mk diff --git a/eth-sender/source/scan.cpp b/eth-sender/source/scan.cpp index 8a28c59e6..a2db1134a 100644 --- a/eth-sender/source/scan.cpp +++ b/eth-sender/source/scan.cpp @@ -39,7 +39,7 @@ bool Similar(const Address &address, const Nibbles &nibbles) { template task Scan(const Brick<32> &root, Code_ &&code, Each_ &&each) { std::set todo; - todo.emplace(Nibbles()); + todo.emplace(); std::set done; diff --git a/min-v8/target.mk b/min-v8/target.mk index 16e270e40..210dae5cf 100644 --- a/min-v8/target.mk +++ b/min-v8/target.mk @@ -246,7 +246,13 @@ cflags += -DU_SHOW_INTERNAL_API #chacks/$(pwd/v8)/src/./profiler/heap-snapshot-generator.cc += s/V8_CC_MSVC/1/ cflags += -mno-ms-bitfields +# this might have to become global if that bitfield is exported +cflags/$(pwd/v8)/ += -Wno-enum-constexpr-conversion + # https://bugs.chromium.org/p/chromium/issues/detail?id=1016945 cflags/$(pwd/v8)/ += -Wno-builtin-assume-aligned-alignment +# XXX: they might have already changed many of these cases +cflags/$(pwd/v8)/ += -Wno-unused-but-set-variable + archive += $(pwd/v8)/ diff --git a/min-wireshark/target.mk b/min-wireshark/target.mk index b33a16ad4..fff915a0f 100644 --- a/min-wireshark/target.mk +++ b/min-wireshark/target.mk @@ -139,6 +139,9 @@ cflags/$(pwd/wireshark)/ += -Wno-pointer-sign # XXX: fwrite used without check; submit patch cflags/$(pwd/wireshark)/ += -Wno-unused-result +# XXX: this is only used if you have libgnutls and I don't know what I think about that :/ +cflags/$(pwd/wireshark)/epan/dissectors/packet-tls-utils.c += -Wno-unused-but-set-variable + cflags/$(pwd/wireshark)/ += -I$(pwd/wireshark)/epan cflags/$(pwd/wireshark)/ += -I$(pwd/wireshark)/epan/dfilter cflags/$(pwd/wireshark)/ += -I$(pwd/wireshark)/epan/dissectors diff --git a/min-zlib/target.mk b/min-zlib/target.mk index 7c3d74884..107c1ef3a 100644 --- a/min-zlib/target.mk +++ b/min-zlib/target.mk @@ -11,8 +11,8 @@ source += $(wildcard $(pwd)/libz/*.c) archive += $(pwd)/libz/ +cflags/$(pwd)/libz/ += -Wno-deprecated-non-prototype cflags/$(pwd)/libz/ += -Wno-unused-function -cflags/$(pwd)/libz/ += -Wno-unused-variable qflags += -DCHROMIUM_ZLIB_NO_CHROMECONF cflags += -I$(pwd)/libz cflags += -I$(pwd)/extra diff --git a/p2p/boost b/p2p/boost index da041154c..ad09f667e 160000 --- a/p2p/boost +++ b/p2p/boost @@ -1 +1 @@ -Subproject commit da041154c6bac1a4aa98254a7d6819059e8ac0b0 +Subproject commit ad09f667e61e18f5c31590941e748ac38e5a81bf diff --git a/p2p/c-ares b/p2p/c-ares index 82c23e4e7..9eb57f2c8 160000 --- a/p2p/c-ares +++ b/p2p/c-ares @@ -1 +1 @@ -Subproject commit 82c23e4e7ea1ae7f442ac2830447cd8a3137bece +Subproject commit 9eb57f2c8beb4e8af590992e56182c0788b9ce0b diff --git a/p2p/source/buffer.hpp b/p2p/source/buffer.hpp index 073de95f1..e43e3a429 100644 --- a/p2p/source/buffer.hpp +++ b/p2p/source/buffer.hpp @@ -817,13 +817,15 @@ class Flat final : Flat(const Buffer &buffer) : data_(nullptr) { - if ((copy_ = !buffer.each([&](const uint8_t *data, size_t size) { + copy_ = !buffer.each([&](const uint8_t *data, size_t size) { if (data_ != nullptr) return false; size_ = size; data_ = data; return true; - }))) { + }); + + if (copy_) { size_ = buffer.size(); // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) const auto data(new uint8_t[size_]); diff --git a/p2p/source/cache.hpp b/p2p/source/cache.hpp index 0aa1d2f80..1b948ea03 100644 --- a/p2p/source/cache.hpp +++ b/p2p/source/cache.hpp @@ -46,7 +46,7 @@ class Cache { } Type_ &operator ()(const Args_ &args) { - std::unique_lock lock(mutex_); + const std::unique_lock lock(mutex_); const auto &cache(cache_.find(args)); if (cache != cache_.end()) return cache->second; diff --git a/p2p/source/category.cpp b/p2p/source/category.cpp index 1704d0515..72268f1ae 100644 --- a/p2p/source/category.cpp +++ b/p2p/source/category.cpp @@ -28,11 +28,13 @@ namespace orc { -// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) -static std::mutex mutex_; -static std::map errors_; -static int index_(0); -// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) +namespace { + // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) + std::mutex mutex_; + std::map errors_; + int index_(0); + // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) +} std::string Category::message(int index) const { try { @@ -43,14 +45,14 @@ std::string Category::message(int index) const { } std::exception_ptr Category::Convert(int index) noexcept { - std::unique_lock lock(mutex_); + const std::unique_lock lock(mutex_); if (const auto error = errors_.extract(index)) return error.mapped(); orc_insist(false); } boost::system::error_code Category::Convert(const std::exception_ptr &error) noexcept { - std::unique_lock lock(mutex_); + const std::unique_lock lock(mutex_); // XXX: clang-tidy might need fixing, as this just bans ?: // NOLINTNEXTLINE(readability-implicit-bool-conversion) while (!errors_.try_emplace(++index_ ?: ++index_, error).second); diff --git a/p2p/source/chain.cpp b/p2p/source/chain.cpp index d2b9d9cf0..8437ad323 100644 --- a/p2p/source/chain.cpp +++ b/p2p/source/chain.cpp @@ -30,13 +30,15 @@ namespace orc { -static std::optional
MaybeAddress(const Json::Value &address) { +namespace { +std::optional
MaybeAddress(const Json::Value &address) { if (address.isNull()) return std::nullopt; return address.asString(); -} +} } -static Nested Verify(const Json::Value &proofs, Brick<32> hash, const Region &path) { +namespace { +Nested Verify(const Json::Value &proofs, Brick<32> hash, const Region &path) { size_t offset(0); orc_assert(!proofs.isNull()); for (auto e(proofs.size()), i(decltype(e)(0)); i != e; ++i) { @@ -73,7 +75,7 @@ static Nested Verify(const Json::Value &proofs, Brick<32> hash, const Region &pa orc_assert(hash == EmptyVector); return nullptr; -} +} } Receipt::Receipt(Json::Value &&value) : height_(To(value["blockNumber"].asString())), @@ -171,7 +173,7 @@ Record::Record(const uint256_t &chain, const Json::Value &value) : std::vector keys; for (const auto &key : entry["storageKeys"]) keys.emplace_back(Bless(key.asString())); - access.emplace_back(decltype(access_)::value_type(entry["address"].asString(), std::move(keys))); + access.emplace_back(entry["address"].asString(), std::move(keys)); } return access; }(), @@ -339,14 +341,15 @@ uint256_t Chain::Get(Json::Value::ArrayIndex index, const Json::Value &storages, return value; } -static Brick<32> Name(const std::string &name) { +namespace { +Brick<32> Name(const std::string &name) { if (name.empty()) return Zero<32>(); const auto period(name.find('.')); if (period == std::string::npos) return HashK(Tie(Zero<32>(), HashK(name))); return HashK(Tie(Name(name.substr(period + 1)), HashK(name.substr(0, period)))); -} +} } task> Chain::New(Endpoint endpoint, Flags flags, uint256_t chain) { co_return Break(std::move(endpoint), std::move(flags), std::move(chain)); diff --git a/p2p/source/cipher.hpp b/p2p/source/cipher.hpp index c1e1c5fae..0e3c70df1 100644 --- a/p2p/source/cipher.hpp +++ b/p2p/source/cipher.hpp @@ -57,7 +57,7 @@ class Encipher { Beam operator ()() const; static Beam All(const EVP_CIPHER *algorithm, const Region &key, const Region &iv, const Buffer &data) { - Encipher cipher(algorithm, key, iv); + const Encipher cipher(algorithm, key, iv); const auto lhs(cipher(data)); const auto rhs(cipher()); return Beam(Tie(lhs, rhs)); @@ -74,7 +74,7 @@ class Decipher { Beam operator ()() const; static Beam All(const EVP_CIPHER *algorithm, const Region &key, const Region &iv, const Buffer &data) { - Decipher cipher(algorithm, key, iv); + const Decipher cipher(algorithm, key, iv); const auto lhs(cipher(data)); const auto rhs(cipher()); return Beam(Tie(lhs, rhs)); diff --git a/p2p/source/crypto.cpp b/p2p/source/crypto.cpp index e314ea14a..c3e6118be 100644 --- a/p2p/source/crypto.cpp +++ b/p2p/source/crypto.cpp @@ -196,11 +196,12 @@ Signature::Signature(const Brick<65> &data) { } -static const secp256k1_context *Curve() { +namespace { +const secp256k1_context *Curve() { // NOLINTNEXTLINE(misc-redundant-expression) - static std::unique_ptr context_{secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY), &secp256k1_context_destroy}; + static const std::unique_ptr context_{secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY), &secp256k1_context_destroy}; return context_.get(); -} +} } bool operator ==(const Key &lhs, const Key &rhs) { const auto context(Curve()); diff --git a/p2p/source/datagram.cpp b/p2p/source/datagram.cpp index b0812606a..4c16d9745 100644 --- a/p2p/source/datagram.cpp +++ b/p2p/source/datagram.cpp @@ -52,8 +52,8 @@ bool Datagram(const Buffer &data, const std::function()); orc_assert(window.size() == boost::endian::big_to_native(udp.len) - sizeof(udp)); - Socket source(boost::endian::big_to_native(ip4.saddr), boost::endian::big_to_native(udp.source)); - Socket destination(boost::endian::big_to_native(ip4.daddr), boost::endian::big_to_native(udp.dest)); + const Socket source(boost::endian::big_to_native(ip4.saddr), boost::endian::big_to_native(udp.source)); + const Socket destination(boost::endian::big_to_native(ip4.daddr), boost::endian::big_to_native(udp.dest)); return code(source, destination, std::move(window)); }, "parsing packet: " << data); } diff --git a/p2p/source/encoding.cpp b/p2p/source/encoding.cpp index 0286d5725..bf56fe69a 100644 --- a/p2p/source/encoding.cpp +++ b/p2p/source/encoding.cpp @@ -36,7 +36,7 @@ std::string utf(const std::u16string &value) { if (value.empty()) return data; data.resize(value.size() * 5); - int writ(WideCharToMultiByte(CP_UTF8, 0, w16(value.data()), Fit(value.size()), &data[0], Fit(data.size() * sizeof(data[0])), nullptr, nullptr)) + const int writ(WideCharToMultiByte(CP_UTF8, 0, w16(value.data()), Fit(value.size()), &data[0], Fit(data.size() * sizeof(data[0])), nullptr, nullptr)) ; orc_assert(writ != 0); data.resize(writ / sizeof(data[0])); @@ -48,7 +48,7 @@ std::u16string utf(const std::string &value) { if (value.empty()) return data; data.resize(value.size()); - int writ(MultiByteToWideChar(CP_UTF8, 0, value.data(), Fit(value.size() * sizeof(value[0])), w16(&data[0]), Fit(data.size()))); + const int writ(MultiByteToWideChar(CP_UTF8, 0, value.data(), Fit(value.size() * sizeof(value[0])), w16(&data[0]), Fit(data.size()))); orc_assert(writ != 0); data.resize(writ); return data; diff --git a/p2p/source/error.hpp b/p2p/source/error.hpp index 23cb548b9..be0368b22 100644 --- a/p2p/source/error.hpp +++ b/p2p/source/error.hpp @@ -47,6 +47,7 @@ class Error final : template Error operator <<(const Type_ &value) && { + // NOLINTNEXTLINE(misc-const-correctness) std::ostringstream data; data << value; what_ += data.str(); @@ -89,10 +90,13 @@ class Error final : orc_log(orc_Log(), "handled error: " << error.what() << std::endl); \ code } catch (...) { code } +// XXX: clang-tidy fails to consider statement expressions +// NOLINTBEGIN(bugprone-assignment-in-if-condition) #define orc_ignore(code) \ ({ bool _failed(false); try code \ orc_catch({ _failed = true; }) \ _failed; }) +// NOLINTEND(bugprone-assignment-in-if-condition) #define orc_except(code) \ try code catch (...) { \ diff --git a/p2p/source/load.cpp b/p2p/source/load.cpp index 8c7f42b5a..c0de53b0a 100644 --- a/p2p/source/load.cpp +++ b/p2p/source/load.cpp @@ -25,11 +25,11 @@ #include #endif +#include + #include #include -#include - #include "syscall.hpp" namespace orc { @@ -42,28 +42,37 @@ void Create(const std::string &path) { #endif } -void Delete(const std::string &file) { - orc_syscall(unlink(file.c_str())); +void Delete(const std::string &path) { + orc_syscall(unlink(path.c_str())); } bool Exists(const std::string &path) { return orc_syscall(access(path.c_str(), F_OK), ENOENT) == 0; } -uint64_t Modified(const std::string &file) { +uint64_t Modified(const std::string &path) { struct stat info{}; - orc_syscall(stat(file.c_str(), &info)); + orc_syscall(stat(path.c_str(), &info)); return info.st_mtime; } -std::string Load(const std::string &file) { orc_block({ +std::string Load(const std::string &path) { orc_block({ + std::ifstream file; + file.exceptions(std::ifstream::failbit | std::ifstream::badbit); + file.open(path, std::ios::binary); + file.seekg(0, std::ios::end); std::string data; - boost::filesystem::load_string_file(file, data); + data.resize(file.tellg()); + file.seekg(0, std::ios::beg); + file.read(data.data(), data.size()); return data; -}, "loading from " << file); } - -void Save(const std::string &file, const std::string &data) { orc_block({ - boost::filesystem::save_string_file(file, data); -}, "saving to " << file); } +}, "loading from " << path); } + +void Save(const std::string &path, const std::string &data) { orc_block({ + std::ofstream file; + file.exceptions(std::ofstream::failbit | std::ofstream::badbit); + file.open(path, std::ios::binary); + file.write(data.data(), data.size()); +}, "saving to " << path); } } diff --git a/p2p/source/load.hpp b/p2p/source/load.hpp index 5d39f8ec1..59a1ed442 100644 --- a/p2p/source/load.hpp +++ b/p2p/source/load.hpp @@ -28,13 +28,13 @@ namespace orc { void Create(const std::string &path); -void Delete(const std::string &file); +void Delete(const std::string &path); bool Exists(const std::string &path); -uint64_t Modified(const std::string &file); +uint64_t Modified(const std::string &path); -std::string Load(const std::string &file); -void Save(const std::string &file, const std::string &data); +std::string Load(const std::string &path); +void Save(const std::string &path, const std::string &data); } diff --git a/p2p/source/local.cpp b/p2p/source/local.cpp index 708efc825..12dca0839 100644 --- a/p2p/source/local.cpp +++ b/p2p/source/local.cpp @@ -67,7 +67,7 @@ class LocalOpening : continue; } - Subset subset(data, writ); + const Subset subset(data, writ); if (Verbose) Log() << "\e[33mRECV " << writ << " " << subset << "\e[0m" << std::endl; drain_.Land(subset, endpoint); diff --git a/p2p/source/log.cpp b/p2p/source/log.cpp index 77898a929..646503c6e 100644 --- a/p2p/source/log.cpp +++ b/p2p/source/log.cpp @@ -82,7 +82,7 @@ Log::~Log() { try { if (log.find('\e') != std::string::npos) log += "\e[0m"; - std::unique_lock lock(mutex_); + const std::unique_lock lock(mutex_); #if 0 #elif defined(__APPLE__) @@ -104,7 +104,7 @@ Log::~Log() { try { } } std::string Cause() { - std::unique_lock lock(mutex_); + const std::unique_lock lock(mutex_); return cause_; } diff --git a/p2p/source/nested.cpp b/p2p/source/nested.cpp index dbb47d77a..7946f46fe 100644 --- a/p2p/source/nested.cpp +++ b/p2p/source/nested.cpp @@ -95,7 +95,7 @@ std::ostream &operator <<(std::ostream &out, const Nested &value) { out << Subset(value.str()); } else { out << '"'; - for (uint8_t c : value.str()) + for (const uint8_t c : value.str()) if (c >= 0x20 && c < 0x80) out << c; else { diff --git a/p2p/source/remote.cpp b/p2p/source/remote.cpp index 1461ef5cf..44334d3e9 100644 --- a/p2p/source/remote.cpp +++ b/p2p/source/remote.cpp @@ -171,14 +171,14 @@ class RemoteCommon { virtual void Land(const Buffer &data, const Socket &socket) = 0; RemoteCommon(const ip4_addr_t &host) { - Core core; + const Core core; pcb_ = udp_new(); orc_assert(pcb_ != nullptr); orc_lwipcall(udp_bind, (pcb_, &host, 0)); } ~RemoteCommon() { - Core core; + const Core core; udp_remove(pcb_); } @@ -195,7 +195,7 @@ class RemoteCommon { } void Shut() noexcept { - Core core; + const Core core; udp_disconnect(pcb_); } }; @@ -217,7 +217,7 @@ class RemoteAssociation : } void Open(const ip4_addr_t &host, uint16_t port) { - Core core; + const Core core; RemoteCommon::Open(core); orc_lwipcall(udp_connect, (pcb_, &host, port)); } @@ -229,7 +229,7 @@ class RemoteAssociation : } task Send(const Buffer &data) override { - Core core; + const Core core; orc_lwipcall(udp_send, (pcb_, Buffers(data))); co_return; } @@ -256,7 +256,7 @@ class RemoteOpening : } void Open() { - Core core; + const Core core; RemoteCommon::Open(core); } @@ -268,7 +268,7 @@ class RemoteOpening : task Send(const Buffer &data, const Socket &socket) override { ip4_addr_t address(socket.Host()); - Core core; + const Core core; orc_lwipcall(udp_sendto, (pcb_, Buffers(data), &address, socket.Port())); co_return; } @@ -302,13 +302,13 @@ class RemoteConnection final : if (error != nullptr) locked_()->error_ = error; else - locked_()->data_.emplace(Beam()); + locked_()->data_.emplace(); read_.set(); } public: RemoteConnection(const ip4_addr_t &host) { - Core core; + const Core core; pcb_ = tcp_new(); orc_assert(pcb_ != nullptr); tcp_arg(pcb_, this); @@ -317,7 +317,7 @@ class RemoteConnection final : } ~RemoteConnection() override { - Core core; + const Core core; if (pcb_ != nullptr) tcp_abort(pcb_); } @@ -426,7 +426,7 @@ class RemoteConnection final : // XXX: provide support for tcp_close and unify with Connection's semantics in Stream via Adapter void Shut() noexcept override { - Core core; + const Core core; orc_insist(pcb_ != nullptr); orc_except({ orc_lwipcall(tcp_shutdown, (pcb_, false, true)); }); } @@ -442,7 +442,7 @@ class RemoteConnection final : co_await Schedule(); start: - Core core; + const Core core; orc_assert(pcb_ != nullptr); const auto need(tcp_sndbuf(pcb_)); @@ -514,14 +514,16 @@ Remote::Remote(const class Host &host) : } ip4_addr_t gateway; IP4_ADDR(&gateway, 10,7,0,1); - ip4_addr_t address(host_); + const ip4_addr_t address(host_); ip4_addr_t netmask; IP4_ADDR(&netmask, 255,255,255,0); orc_lwipcall(netifapi_netif_add, (&interface_, &address, &netmask, &gateway, this, &Initialize, &ip_input)); } -// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) -static uint8_t quad_(3); +namespace { + // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) + uint8_t quad_(3); +} Remote::Remote() : Remote({10,7,0,++quad_}) diff --git a/p2p/source/scope.hpp b/p2p/source/scope.hpp index 3f48a665e..29d8f8516 100644 --- a/p2p/source/scope.hpp +++ b/p2p/source/scope.hpp @@ -92,7 +92,7 @@ class scope { #endif #define _scope__(code, line) \ - scope _scope ## line([&]code) + const scope _scope ## line([&]code) #define _scope_(code, line) \ _scope__(code, line) #define _scope(code) \ diff --git a/p2p/source/spawn.cpp b/p2p/source/spawn.cpp index 05b8cdf9b..32feeabdf 100644 --- a/p2p/source/spawn.cpp +++ b/p2p/source/spawn.cpp @@ -36,7 +36,7 @@ Pool::Pool() : for (;ready_.reset(), true; ready_.wait()) for (;;) { Work *work; - { std::unique_lock lock(mutex_); + { const std::unique_lock lock(mutex_); if (end_ == nullptr) return; if (begin_ == nullptr) @@ -53,14 +53,14 @@ Pool::Pool() : } Pool::~Pool() { - { std::unique_lock lock(mutex_); + { const std::unique_lock lock(mutex_); end_ = nullptr; } ready_.set(); thread_.join(); } void Pool::Push(Work *work) noexcept { - { std::unique_lock lock(mutex_); + { const std::unique_lock lock(mutex_); if (end_ == nullptr) return; *end_ = work; end_ = &work->next_; } diff --git a/p2p/source/store.cpp b/p2p/source/store.cpp index 352e0d77e..cce07daf6 100644 --- a/p2p/source/store.cpp +++ b/p2p/source/store.cpp @@ -39,7 +39,7 @@ std::string Stringify(bssl::UniquePtr bio) { char *data; // BIO_get_mem_data is an inline macro with a char * cast // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast) - size_t size(BIO_get_mem_data(bio.get(), &data)); + const size_t size(BIO_get_mem_data(bio.get(), &data)); return {data, size}; } @@ -51,7 +51,7 @@ Store::Store(std::string key, std::string certificates) : Store::Store(const std::string &store) { bssl::UniquePtr p12([&]() { - bssl::UniquePtr bio(BIO_new_mem_buf(store.data(), Fit(store.size()))); + const bssl::UniquePtr bio(BIO_new_mem_buf(store.data(), Fit(store.size()))); orc_assert(bio); return d2i_PKCS12_bio(bio.get(), nullptr); diff --git a/p2p/source/syscall.hpp b/p2p/source/syscall.hpp index 7d862f248..80f309ba7 100644 --- a/p2p/source/syscall.hpp +++ b/p2p/source/syscall.hpp @@ -33,11 +33,13 @@ #endif // XXX: this is *ridiculous*, but lambdas break structured binding :/ +// XXX: clang-tidy fails to consider statement expressions +// NOLINTBEGIN(bugprone-assignment-in-if-condition) #define orc_syscall(expr, ...) ({ decltype(expr) _value; for (;;) { \ _value = (expr); \ if ((long) _value != -1) \ break; \ - int error(orc_errno); \ + const int error(orc_errno); \ _value = 0; \ for (auto success : std::initializer_list{__VA_ARGS__}) \ if (error == success) \ @@ -48,6 +50,7 @@ continue; \ orc_throw(error << "=\"" << strerror(error) << "\" calling " << #expr); \ } _value; }) +// NOLINTEND(bugprone-assignment-in-if-condition) #define orc_packed \ __attribute__((__packed__)) diff --git a/p2p/source/threads.cpp b/p2p/source/threads.cpp index bf777db32..b5eb50f4c 100644 --- a/p2p/source/threads.cpp +++ b/p2p/source/threads.cpp @@ -25,7 +25,7 @@ namespace orc { const Threads &Threads::Get() { - static Threads threads; + static const Threads threads; return threads; } diff --git a/p2p/source/time.cpp b/p2p/source/time.cpp index 4452b1359..52684a24d 100644 --- a/p2p/source/time.cpp +++ b/p2p/source/time.cpp @@ -28,15 +28,15 @@ namespace orc { uint64_t Monotonic() { using std::chrono::system_clock; - system_clock::time_point point(system_clock::now()); - system_clock::duration duration(point.time_since_epoch()); + const system_clock::time_point point(system_clock::now()); + const system_clock::duration duration(point.time_since_epoch()); return std::chrono::duration_cast(duration).count(); } uint64_t Timestamp() { using std::chrono::system_clock; - system_clock::time_point point(system_clock::now()); - system_clock::duration duration(point.time_since_epoch()); + const system_clock::time_point point(system_clock::now()); + const system_clock::duration duration(point.time_since_epoch()); return std::chrono::duration_cast(duration).count(); } diff --git a/p2p/source/trace.cpp b/p2p/source/trace.cpp index 44b70720b..2a8c80fd7 100644 --- a/p2p/source/trace.cpp +++ b/p2p/source/trace.cpp @@ -60,7 +60,7 @@ void Trace(const char *type, bool send, bool deep, const Buffer &data) { try { (tcp.flags & (1 << 0)) == 0 ? '.' : 'F', '\0'}; - std::unique_lock lock(mutex_); + const std::unique_lock lock(mutex_); // clang-tidy somehow treats ORC_TRACE as an integer?!? // NOLINTNEXTLINE(readability-implicit-bool-conversion) diff --git a/p2p/source/transport.cpp b/p2p/source/transport.cpp index 38c5c3ebc..5ff2e10d5 100644 --- a/p2p/source/transport.cpp +++ b/p2p/source/transport.cpp @@ -77,7 +77,7 @@ class Transport : protected: void Land(const Buffer &data) override { - static size_t payload(65536); + static const size_t payload(65536); const auto size(data.size()); orc_assert_(size <= payload, "orc_assert(Land: " << size << " {data.size()} <= " << payload << ") " << data); //Log() << "\e[33mRECV " << data.size() << " " << data << "\e[0m" << std::endl; @@ -165,6 +165,7 @@ class Transport : } bool transport_send_const(const openvpn::Buffer &data) noexcept override { + // XXX: NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) nest_.Hatch([&]() noexcept { return [this, buffer = Beam(data.c_data(), data.size())]() -> task { //Log() << "\e[35mSEND " << buffer.size() << " " << buffer << "\e[0m" << std::endl; co_await Inner().Send(buffer); @@ -177,7 +178,7 @@ class Transport : bool transport_send(openvpn::BufferAllocated &buffer) noexcept override { nest_.Hatch([&]() noexcept { return [this, buffer = std::move(buffer)]() -> task { - Subset data(buffer.c_data(), buffer.size()); + const Subset data(buffer.c_data(), buffer.size()); //Log() << "\e[35mSEND " << data.size() << " " << data << "\e[0m" << std::endl; co_await Inner().Send(data); }; }, __FUNCTION__); @@ -228,7 +229,7 @@ class Factory : } openvpn::TransportClient::Ptr new_transport_client_obj(openvpn_io::io_context &context, openvpn::TransportClientParent *parent) noexcept override { - openvpn::RCPtr transport(new BufferSink(base_, config_, context, parent)); + const openvpn::RCPtr transport(new BufferSink(base_, config_, context, parent)); transport->Open(*transport); return transport; } @@ -294,7 +295,7 @@ class Middle : bool tun_send(openvpn::BufferAllocated &buffer) noexcept override { if (orc_ignore({ middle_.Forge(buffer); })) return false; - Subset data(buffer.c_data(), buffer.size()); + const Subset data(buffer.c_data(), buffer.size()); middle_.Land(data); return true; } diff --git a/p2p/source/trezor.cpp b/p2p/source/trezor.cpp index 317a1296d..abeb4d111 100644 --- a/p2p/source/trezor.cpp +++ b/p2p/source/trezor.cpp @@ -33,11 +33,12 @@ namespace orc { namespace tzr = hw::trezor::messages; #define ORC_TREZOR(space, type) Call -static task Trezor(const S &base, const std::string &path, const std::string &data = {}) { +namespace { +task Trezor(const S &base, const std::string &path, const std::string &data = {}) { co_return (co_await base->Fetch("POST", {{"http", "localhost", "21325"}, path}, { {"origin", "https://connect.trezor.io"}, }, data)).ok(); -} +} } TrezorSession::TrezorSession(S base, std::string session) : Valve(typeid(*this).name()), @@ -131,11 +132,12 @@ task TrezorSession::Call(uint16_t type, const Request_ &request) cons } } +namespace { template -static void Trezor(Request_ &request, const std::vector &indices) { +void Trezor(Request_ &request, const std::vector &indices) { for (const auto &index : indices) request.add_address_n(index); -} +} } TrezorExecutor::TrezorExecutor(S session, std::vector indices, Address address) : session_(std::move(session)), diff --git a/p2p/source/valve.cpp b/p2p/source/valve.cpp index c0fc3188f..f78eab8e6 100644 --- a/p2p/source/valve.cpp +++ b/p2p/source/valve.cpp @@ -46,18 +46,18 @@ struct Tracker { class Track { private: Tracker &tracker_; - std::unique_lock lock_; + const std::unique_lock lock_; public: Track() : tracker_([]() -> Tracker & { static Tracker tracker; - static std::thread thread([]() { + static const std::thread thread([]() { for (;;) { sleep(5); - std::unique_lock lock(tracker.mutex_); + const std::unique_lock lock(tracker.mutex_); Log() << "^^^^^^^^^^^^^^^^" << std::endl; for (const auto valve : tracker.valves_) Log() << std::setw(5) << valve->unique_ << ": " << boost::core::demangle(typeid(*valve).name()) << std::endl; diff --git a/srv-daemon/source/lottery0.hpp b/srv-daemon/source/lottery0.hpp index e28e5689d..97af25649 100644 --- a/srv-daemon/source/lottery0.hpp +++ b/srv-daemon/source/lottery0.hpp @@ -74,7 +74,7 @@ class Lottery0 : template void Send(const S &executor, Args_ &&...args) { - static Selector Credit(const uint256_t &now, const uint256_t &start, const uint128_t &range, const uint128_t &amount, const uint128_t &ratio, const uint64_t &gas) const; void Send(const S &executor, const Address &recipient, const Payment1 &payment) { - static Selector /*payments*/, diff --git a/srv-daemon/source/main.cpp b/srv-daemon/source/main.cpp index 41daa826b..8d5492771 100644 --- a/srv-daemon/source/main.cpp +++ b/srv-daemon/source/main.cpp @@ -167,7 +167,7 @@ int Main(int argc, const char *const argv[]) { ("wireguard", po::value(), "WireGuard .conf configuration file") ; options.add(group); } - po::positional_options_description positional; + const po::positional_options_description positional; po::store(po::command_line_parser(argc, argv).options(po::options_description() .add(group) @@ -233,7 +233,7 @@ int Main(int argc, const char *const argv[]) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast) //U identity(static_cast(rtc::OpenSSLIdentity::FromPEMStrings(store.Key(), store.Certificates())); - rtc::scoped_refptr certificate(rtc::RTCCertificate::FromPEM(rtc::RTCCertificatePEM(store.Key(), store.Certificates()))); + const rtc::scoped_refptr certificate(rtc::RTCCertificate::FromPEM(rtc::RTCCertificatePEM(store.Key(), store.Certificates()))); U fingerprint(rtc::SSLFingerprint::CreateFromCertificate(*certificate)); @@ -248,7 +248,7 @@ int Main(int argc, const char *const argv[]) { //return TestWorker(asio::ip::make_address(args["bind"].as()), port, store.Key(), store.Certificates(), params); const Strung url("https://" + host + ":" + std::to_string(port) + "/"); - Bytes gpg; + const Bytes gpg; Builder tls; static const std::regex re("-"); @@ -292,7 +292,7 @@ int Main(int argc, const char *const argv[]) { for (const auto &market : markets) if (*market.chain_ == 1) { const Address contract(args["lottery0"].as()); - static Selector
what_("what"); + static const Selector
what_("what"); auto lottery0(Break(Token{market, co_await what_.Call(*market.chain_, "latest", contract, 90000), diff --git a/srv-daemon/source/node.cpp b/srv-daemon/source/node.cpp index fd92d9ae5..98c0f2ae0 100644 --- a/srv-daemon/source/node.cpp +++ b/srv-daemon/source/node.cpp @@ -43,7 +43,7 @@ void Node::Run(const asio::ip::address &bind, uint16_t port, const std::string & const auto offer(request.body()); // XXX: look up fingerprint static int fingerprint_(0); - std::string fingerprint(std::to_string(fingerprint_++)); + const std::string fingerprint(std::to_string(fingerprint_++)); const auto server(Find(fingerprint)); auto answer(co_await server->Respond(base_, offer, ice_)); diff --git a/srv-kernel/source/main.cpp b/srv-kernel/source/main.cpp index 561309885..a19f602c5 100644 --- a/srv-kernel/source/main.cpp +++ b/srv-kernel/source/main.cpp @@ -20,6 +20,7 @@ /* }}} */ +#include #include #include @@ -54,7 +55,8 @@ size_t strlen(const char *data) { } // snprintf {{{ -static char *itoa_(uintmax_t value, char *data, unsigned int base, bool upper) { +namespace { +char *itoa_(uintmax_t value, char *data, unsigned int base, bool upper) { if (value == 0) *--data = '0'; else while (value != 0) { @@ -64,7 +66,7 @@ static char *itoa_(uintmax_t value, char *data, unsigned int base, bool upper) { } return data; -} +} } // NOLINTBEGIN(cppcoreguidelines-pro-type-vararg) size_t vsnprintf(char *str, size_t max, const char *format, va_list args) { diff --git a/srv-worker/source/main.cpp b/srv-worker/source/main.cpp index 1d394dabb..f4c14a06a 100644 --- a/srv-worker/source/main.cpp +++ b/srv-worker/source/main.cpp @@ -35,7 +35,7 @@ void Test(const v8::FunctionCallbackInfo &args) { //const auto context(isolate->GetCurrentContext()); //orc_assert(args.Length() == 1); v8::String::Utf8Value arg0(isolate, args[0]); - std::string value(*arg0, arg0.length()); + const std::string value(*arg0, arg0.length()); std::cerr << value << std::endl; (void) value; } @@ -50,7 +50,7 @@ int main(int argc, char *argv[], char **envp) { // XXX: this is not security critical for our daemon, but might have effects on user code // there isn't a good source of entropy right now in the worker process; I should add one // NOLINTNEXTLINE(cert-msc32-c,cert-msc51-cpp) - static std::independent_bits_engine engine; + static const std::independent_bits_engine engine; std::generate(data, data + size, engine); return true; }); @@ -73,12 +73,12 @@ int main(int argc, char *argv[], char **envp) { }())); _scope({ isolate->Dispose(); }); - v8::Locker locker(isolate); - v8::Isolate::Scope isolated(isolate); - v8::HandleScope scope(isolate); + const v8::Locker locker(isolate); + const v8::Isolate::Scope isolated(isolate); + const v8::HandleScope scope(isolate); const auto context(v8::Context::New(isolate)); - v8::Context::Scope contextualized(context); + const v8::Context::Scope contextualized(context); const auto global(context->Global()); (void) global->Set(context, v8::String::NewFromUtf8Literal(isolate, "test"), v8::Function::New(context, &Test).ToLocalChecked()); diff --git a/vpn-shared/source/capture.cpp b/vpn-shared/source/capture.cpp index 81427778d..1fb56a8dd 100644 --- a/vpn-shared/source/capture.cpp +++ b/vpn-shared/source/capture.cpp @@ -679,7 +679,8 @@ BufferSunk &Capture::Start() { return backup; } -static JSValue Print(JSContext *context, JSValueConst self, int argc, JSValueConst *argv) { try { +namespace { +JSValue Print(JSContext *context, JSValueConst self, int argc, JSValueConst *argv) { try { orc_assert(argc == 1); size_t size; const auto data(JS_ToCStringLen(context, &size, argv[0])); @@ -691,9 +692,10 @@ static JSValue Print(JSContext *context, JSValueConst self, int argc, JSValueCon } catch (const std::exception &error) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) return JS_ThrowInternalError(context, "%s", error.what()); -} } +} } } -static task Single(BufferSunk &sunk, Heap &heap, const S &network, const S ðereum, const S &base, const Host &local, unsigned hop, const boost::filesystem::path &group, const Locator &locator, const S> &oracle, const Token &oxt) { orc_block({ +namespace { +task Single(BufferSunk &sunk, Heap &heap, const S &network, const S ðereum, const S &base, const Host &local, unsigned hop, const boost::filesystem::path &group, const Locator &locator, const S> &oracle, const Token &oxt) { orc_block({ const std::string hops("hops[" + std::to_string(hop) + "]"); const auto protocol(heap.eval(hops + ".protocol")); if (false) { @@ -729,7 +731,7 @@ static task Single(BufferSunk &sunk, Heap &heap, const S &network } else if (protocol == "wireguard") { co_await Guard(sunk, base, local.operator uint32_t(), heap.eval(hops + ".config")); } else orc_assert_(false, "unknown hop protocol: " << protocol); -}, "building hop #" << hop); } +}, "building hop #" << hop); } } void Capture::Start(const std::string &path) { Heap heap; { diff --git a/vpn-windows/source/protect.cpp b/vpn-windows/source/protect.cpp index aba2e5dd9..57991158d 100644 --- a/vpn-windows/source/protect.cpp +++ b/vpn-windows/source/protect.cpp @@ -35,7 +35,7 @@ DWORD getTunIndex() { auto pAddresses = reinterpret_cast(addresses.get()); for (;;) { - DWORD r = GetAdaptersAddresses(AF_INET, + const DWORD r = GetAdaptersAddresses(AF_INET, GAA_FLAG_SKIP_ANYCAST|GAA_FLAG_SKIP_MULTICAST| GAA_FLAG_SKIP_DNS_SERVER|GAA_FLAG_SKIP_FRIENDLY_NAME, nullptr, pAddresses, &dwSize); @@ -78,7 +78,7 @@ std::pair default_gateway_outside_tun(u_long dest) auto pIpForwardTable = reinterpret_cast(ipForwardTable.get()); for (;;) { - DWORD r = GetIpForwardTable(pIpForwardTable, &dwSize, 0); + const DWORD r = GetIpForwardTable(pIpForwardTable, &dwSize, 0); if (r == ERROR_INSUFFICIENT_BUFFER) { ipForwardTable = std::make_unique(dwSize); pIpForwardTable = reinterpret_cast(ipForwardTable.get()); @@ -95,7 +95,7 @@ std::pair default_gateway_outside_tun(u_long dest) break; } - DWORD tunIndex = getTunIndex(); + const DWORD tunIndex = getTunIndex(); DWORD prefix = 0; DWORD index = -1; DWORD metric = ULONG_MAX; @@ -112,7 +112,7 @@ std::pair default_gateway_outside_tun(u_long dest) if (!SUBNET_EQ(row->dwForwardDest, row->dwForwardMask, dest)) { continue; } - DWORD forwardPrefix = dest & row->dwForwardMask; + const DWORD forwardPrefix = dest & row->dwForwardMask; if (forwardPrefix > prefix || (forwardPrefix == prefix && row->dwForwardMetric1 < metric)) { prefix = forwardPrefix; index = row->dwForwardIfIndex; @@ -130,7 +130,7 @@ std::unique_ptr get_addr_by_index(DWORD index) auto pAddresses = reinterpret_cast(addresses.get()); for (;;) { - DWORD r = GetAdaptersAddresses(AF_INET, + const DWORD r = GetAdaptersAddresses(AF_INET, GAA_FLAG_SKIP_ANYCAST|GAA_FLAG_SKIP_MULTICAST| GAA_FLAG_SKIP_DNS_SERVER|GAA_FLAG_SKIP_FRIENDLY_NAME, nullptr, pAddresses, &dwSize); @@ -175,7 +175,7 @@ int Protect(SOCKET socket, int (*attach)(SOCKET, const sockaddr *, socklen_t), c auto pAddresses = reinterpret_cast(addresses.get()); for (;;) { - DWORD r = GetAdaptersAddresses(AF_INET, + const DWORD r = GetAdaptersAddresses(AF_INET, GAA_FLAG_SKIP_ANYCAST|GAA_FLAG_SKIP_MULTICAST| GAA_FLAG_SKIP_DNS_SERVER|GAA_FLAG_SKIP_FRIENDLY_NAME, nullptr, pAddresses, &dwSize); diff --git a/vpn-windows/source/tunnel.cpp b/vpn-windows/source/tunnel.cpp index c4a448ca8..adcdd7a09 100644 --- a/vpn-windows/source/tunnel.cpp +++ b/vpn-windows/source/tunnel.cpp @@ -175,8 +175,8 @@ void Tunnel(BufferSunk &sunk, const std::string &device, const std::function