From fa18fc705084f3620be566d8c6639b29117ccf68 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Fri, 19 Jul 2024 15:23:28 +0200 Subject: [PATCH] log: Remove NOLINT(bitcoin-unterminated-logprintf) --- src/dbwrapper.cpp | 2 +- src/util/string.h | 8 ++++++++ src/wallet/wallet.cpp | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp index 775496e21bd..479064d4688 100644 --- a/src/dbwrapper.cpp +++ b/src/dbwrapper.cpp @@ -100,7 +100,7 @@ public: assert(p <= limit); base[std::min(bufsize - 1, (int)(p - base))] = '\0'; - LogPrintLevel(BCLog::LEVELDB, BCLog::Level::Debug, "%s", base); // NOLINT(bitcoin-unterminated-logprintf) + LogDebug(BCLog::LEVELDB, "%s\n", util::RemoveSuffixView(base, "\n")); if (base != buffer) { delete[] base; } diff --git a/src/util/string.h b/src/util/string.h index e2e470f4ab5..30c0a0d6c1c 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -81,6 +81,14 @@ std::vector Split(const Span& sp, char sep) return std::string(TrimStringView(str, pattern)); } +[[nodiscard]] inline std::string_view RemoveSuffixView(std::string_view str, std::string_view suffix) +{ + if (str.ends_with(suffix)) { + return str.substr(0, str.size() - suffix.size()); + } + return str; +} + [[nodiscard]] inline std::string_view RemovePrefixView(std::string_view str, std::string_view prefix) { if (str.substr(0, prefix.size()) == prefix) { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index bb1789f109e..8e31950bebc 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2309,7 +2309,7 @@ OutputType CWallet::TransactionChangeType(const std::optional& chang void CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector> orderForm) { LOCK(cs_wallet); - WalletLogPrintf("CommitTransaction:\n%s", tx->ToString()); // NOLINT(bitcoin-unterminated-logprintf) + WalletLogPrintf("CommitTransaction:\n%s\n", util::RemoveSuffixView(tx->ToString(), "\n")); // Add tx to wallet, because if it has change it's also ours, // otherwise just for transaction history.