mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 03:47:29 -03:00
Merge bitcoin/bitcoin#30485: log: Remove NOLINT(bitcoin-unterminated-logprintf)
fa18fc7050
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 (https://github.com/bitcoin/bitcoin/pull/30386#discussion_r1682963306). 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: ACKfa18fc7050
ryanofsky: Code review ACKfa18fc7050
Tree-SHA512: bf8a83723cca84e21187658edc19612da79c34f7ef2e1f6e9353e7ba70e4ecc0a878a2ae32290045fb90cba9a44451e35341a36ef2ec1169d13592393aa4a8ca
This commit is contained in:
commit
bb25e0691f
3 changed files with 10 additions and 2 deletions
|
@ -100,7 +100,7 @@ public:
|
||||||
|
|
||||||
assert(p <= limit);
|
assert(p <= limit);
|
||||||
base[std::min(bufsize - 1, (int)(p - base))] = '\0';
|
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) {
|
if (base != buffer) {
|
||||||
delete[] base;
|
delete[] base;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,6 +81,14 @@ std::vector<T> Split(const Span<const char>& sp, char sep)
|
||||||
return std::string(TrimStringView(str, pattern));
|
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)
|
[[nodiscard]] inline std::string_view RemovePrefixView(std::string_view str, std::string_view prefix)
|
||||||
{
|
{
|
||||||
if (str.substr(0, prefix.size()) == prefix) {
|
if (str.substr(0, prefix.size()) == prefix) {
|
||||||
|
|
|
@ -2309,7 +2309,7 @@ OutputType CWallet::TransactionChangeType(const std::optional<OutputType>& chang
|
||||||
void CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm)
|
void CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm)
|
||||||
{
|
{
|
||||||
LOCK(cs_wallet);
|
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,
|
// Add tx to wallet, because if it has change it's also ours,
|
||||||
// otherwise just for transaction history.
|
// otherwise just for transaction history.
|
||||||
|
|
Loading…
Reference in a new issue