Skip to content

Commit

Permalink
refactor: Enforce C-str fmt strings in WalletLogPrintf()
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoFalke committed Aug 8, 2023
1 parent fa244f3 commit fa6dc57
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions contrib/devtools/bitcoin-tidy/example_logprintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class CWallet

public:
template <typename... Params>
void WalletLogPrintf(std::string fmt, Params... parameters) const
void WalletLogPrintf(const char* fmt, Params... parameters) const
{
LogPrintf(("%s " + fmt).c_str(), GetDisplayName(), parameters...);
LogPrintf(("%s " + std::string{fmt}).c_str(), GetDisplayName(), parameters...);
};
};

Expand Down
7 changes: 4 additions & 3 deletions src/wallet/scriptpubkeyman.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,10 @@ class ScriptPubKeyMan
virtual std::unordered_set<CScript, SaltedSipHasher> GetScriptPubKeys() const { return {}; };

/** Prepends the wallet name in logging output to ease debugging in multi-wallet use cases */
template<typename... Params>
void WalletLogPrintf(std::string fmt, Params... parameters) const {
LogPrintf(("%s " + fmt).c_str(), m_storage.GetDisplayName(), parameters...);
template <typename... Params>
void WalletLogPrintf(const char* fmt, Params... parameters) const
{
LogPrintf(("%s " + std::string{fmt}).c_str(), m_storage.GetDisplayName(), parameters...);
};

/** Watch-only address added */
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2319,7 +2319,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)
{
LOCK(cs_wallet);
WalletLogPrintf("CommitTransaction:\n%s", tx->ToString());
WalletLogPrintf("CommitTransaction:\n%s", tx->ToString()); // NOLINT(bitcoin-unterminated-logprintf)

// Add tx to wallet, because if it has change it's also ours,
// otherwise just for transaction history.
Expand Down
7 changes: 4 additions & 3 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -890,9 +890,10 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
};

/** Prepends the wallet name in logging output to ease debugging in multi-wallet use cases */
template<typename... Params>
void WalletLogPrintf(std::string fmt, Params... parameters) const {
LogPrintf(("%s " + fmt).c_str(), GetDisplayName(), parameters...);
template <typename... Params>
void WalletLogPrintf(const char* fmt, Params... parameters) const
{
LogPrintf(("%s " + std::string{fmt}).c_str(), GetDisplayName(), parameters...);
};

/** Upgrade the wallet */
Expand Down
8 changes: 4 additions & 4 deletions test/lint/run-lint-format-strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
("src/clientversion.cpp", "strprintf(_(COPYRIGHT_HOLDERS).translated, COPYRIGHT_HOLDERS_SUBSTITUTION)"),
("src/test/translation_tests.cpp", "strprintf(format, arg)"),
("src/validationinterface.cpp", "LogPrint(BCLog::VALIDATION, fmt \"\\n\", __VA_ARGS__)"),
("src/wallet/wallet.h", "WalletLogPrintf(std::string fmt, Params... parameters)"),
("src/wallet/wallet.h", "LogPrintf((\"%s \" + fmt).c_str(), GetDisplayName(), parameters...)"),
("src/wallet/scriptpubkeyman.h", "WalletLogPrintf(std::string fmt, Params... parameters)"),
("src/wallet/scriptpubkeyman.h", "LogPrintf((\"%s \" + fmt).c_str(), m_storage.GetDisplayName(), parameters...)"),
("src/wallet/wallet.h", "WalletLogPrintf(const char* fmt, Params... parameters)"),
("src/wallet/wallet.h", "LogPrintf((\"%s \" + std::string{fmt}).c_str(), GetDisplayName(), parameters...)"),
("src/wallet/scriptpubkeyman.h", "WalletLogPrintf(const char* fmt, Params... parameters)"),
("src/wallet/scriptpubkeyman.h", "LogPrintf((\"%s \" + std::string{fmt}).c_str(), m_storage.GetDisplayName(), parameters...)"),
]


Expand Down

0 comments on commit fa6dc57

Please sign in to comment.