0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-08 10:31:50 -05:00

util: Use compile-time check for FatalErrorf

This commit is contained in:
MarcoFalke 2024-07-30 14:30:16 +02:00
parent faa62c0112
commit fa7087b896
No known key found for this signature in database
5 changed files with 15 additions and 7 deletions

View file

@ -1,4 +1,4 @@
// Copyright (c) 2017-2022 The Bitcoin Core developers
// Copyright (c) 2017-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -14,6 +14,7 @@
#include <node/database_args.h>
#include <node/interface_ui.h>
#include <tinyformat.h>
#include <util/string.h>
#include <util/thread.h>
#include <util/translation.h>
#include <validation.h> // For g_chainman
@ -27,7 +28,7 @@ constexpr auto SYNC_LOG_INTERVAL{30s};
constexpr auto SYNC_LOCATOR_WRITE_INTERVAL{30s};
template <typename... Args>
void BaseIndex::FatalErrorf(const char* fmt, const Args&... args)
void BaseIndex::FatalErrorf(util::ConstevalFormatString<sizeof...(Args)> fmt, const Args&... args)
{
auto message = tfm::format(fmt, args...);
node::AbortNode(m_chain->context()->shutdown, m_chain->context()->exit_status, Untranslated(message), m_chain->context()->warnings.get());

View file

@ -1,4 +1,4 @@
// Copyright (c) 2017-2022 The Bitcoin Core developers
// Copyright (c) 2017-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -7,6 +7,7 @@
#include <dbwrapper.h>
#include <interfaces/chain.h>
#include <util/string.h>
#include <util/threadinterrupt.h>
#include <validationinterface.h>
@ -94,7 +95,7 @@ private:
virtual bool AllowPrune() const = 0;
template <typename... Args>
void FatalErrorf(const char* fmt, const Args&... args);
void FatalErrorf(util::ConstevalFormatString<sizeof...(Args)> fmt, const Args&... args);
protected:
std::unique_ptr<interfaces::Chain> m_chain;

View file

@ -6,6 +6,7 @@
#define BITCOIN_UTIL_STRING_H
#include <span.h>
#include <tinyformat.h>
#include <array>
#include <cstdint>
@ -234,4 +235,12 @@ template <typename T1, size_t PREFIX_LEN>
}
} // namespace util
namespace tinyformat {
template <typename... Args>
std::string format(util::ConstevalFormatString<sizeof...(Args)> fmt, const Args&... args)
{
return format(fmt.fmt, args...);
}
} // namespace tinyformat
#endif // BITCOIN_UTIL_STRING_H

View file

@ -16,7 +16,6 @@ import re
import sys
FUNCTION_NAMES_AND_NUMBER_OF_LEADING_ARGUMENTS = [
'FatalErrorf,0',
'tfm::format,1', # Assuming tfm::::format(std::ostream&, ...
'LogConnectFailure,1',
'LogError,0',

View file

@ -13,8 +13,6 @@ import re
import sys
FALSE_POSITIVES = [
("src/index/base.cpp", "FatalErrorf(const char* fmt, const Args&... args)"),
("src/index/base.h", "FatalErrorf(const char* fmt, const Args&... args)"),
("src/netbase.cpp", "LogConnectFailure(bool manual_connection, const char* fmt, const Args&... args)"),
("src/clientversion.cpp", "strprintf(_(COPYRIGHT_HOLDERS).translated, COPYRIGHT_HOLDERS_SUBSTITUTION)"),
("src/test/translation_tests.cpp", "strprintf(format, arg)"),