Skip to content

Commit bb25e06

Browse files
committed
Merge bitcoin#30485: log: Remove NOLINT(bitcoin-unterminated-logprintf)
fa18fc7 log: Remove NOLINT(bitcoin-unterminated-logprintf) (MarcoFalke) Pull request description: `NOLINT(bitcoin-unterminated-logprintf)` is used to document a missing trailing `\n` char in the format string. This has many issues: * It is just documentation, assuming that a trailing `\n` ends up in the formatted string. It is not enforced at compile-time, so it is brittle. * If the newline was truly missing and `NOLINT(bitcoin-unterminated-logprintf)` were used to document a "continued" line, the log stream would be racy/corrupt, because any other thread may inject a log message in the meantime. * If the newline was accidentally missing, nothing is there to correct the mistake. * The intention of all code is to always end a log line with a new line. However, historic code exists to deal with the case where the new line was missing (`m_started_new_line`). This is problematic, because the presumed dead code has to be maintained (bitcoin#30386 (comment)). Fix almost all issues by removing the `NOLINT(bitcoin-unterminated-logprintf)`, ensuring that a new line is always present. A follow-up will remove the dead logging code. ACKs for top commit: TheCharlatan: ACK fa18fc7 ryanofsky: Code review ACK fa18fc7 Tree-SHA512: bf8a83723cca84e21187658edc19612da79c34f7ef2e1f6e9353e7ba70e4ecc0a878a2ae32290045fb90cba9a44451e35341a36ef2ec1169d13592393aa4a8ca
2 parents d7333ec + fa18fc7 commit bb25e06

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/dbwrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class CBitcoinLevelDBLogger : public leveldb::Logger {
100100

101101
assert(p <= limit);
102102
base[std::min(bufsize - 1, (int)(p - base))] = '\0';
103-
LogPrintLevel(BCLog::LEVELDB, BCLog::Level::Debug, "%s", base); // NOLINT(bitcoin-unterminated-logprintf)
103+
LogDebug(BCLog::LEVELDB, "%s\n", util::RemoveSuffixView(base, "\n"));
104104
if (base != buffer) {
105105
delete[] base;
106106
}

src/util/string.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ std::vector<T> Split(const Span<const char>& sp, char sep)
8181
return std::string(TrimStringView(str, pattern));
8282
}
8383

84+
[[nodiscard]] inline std::string_view RemoveSuffixView(std::string_view str, std::string_view suffix)
85+
{
86+
if (str.ends_with(suffix)) {
87+
return str.substr(0, str.size() - suffix.size());
88+
}
89+
return str;
90+
}
91+
8492
[[nodiscard]] inline std::string_view RemovePrefixView(std::string_view str, std::string_view prefix)
8593
{
8694
if (str.substr(0, prefix.size()) == prefix) {

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2309,7 +2309,7 @@ OutputType CWallet::TransactionChangeType(const std::optional<OutputType>& chang
23092309
void CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm)
23102310
{
23112311
LOCK(cs_wallet);
2312-
WalletLogPrintf("CommitTransaction:\n%s", tx->ToString()); // NOLINT(bitcoin-unterminated-logprintf)
2312+
WalletLogPrintf("CommitTransaction:\n%s\n", util::RemoveSuffixView(tx->ToString(), "\n"));
23132313

23142314
// Add tx to wallet, because if it has change it's also ours,
23152315
// otherwise just for transaction history.

0 commit comments

Comments
 (0)