Skip to content

Commit fa7087b

Browse files
author
MarcoFalke
committed
util: Use compile-time check for FatalErrorf
1 parent faa62c0 commit fa7087b

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

src/index/base.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2022 The Bitcoin Core developers
1+
// Copyright (c) 2017-present The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -14,6 +14,7 @@
1414
#include <node/database_args.h>
1515
#include <node/interface_ui.h>
1616
#include <tinyformat.h>
17+
#include <util/string.h>
1718
#include <util/thread.h>
1819
#include <util/translation.h>
1920
#include <validation.h> // For g_chainman
@@ -27,7 +28,7 @@ constexpr auto SYNC_LOG_INTERVAL{30s};
2728
constexpr auto SYNC_LOCATOR_WRITE_INTERVAL{30s};
2829

2930
template <typename... Args>
30-
void BaseIndex::FatalErrorf(const char* fmt, const Args&... args)
31+
void BaseIndex::FatalErrorf(util::ConstevalFormatString<sizeof...(Args)> fmt, const Args&... args)
3132
{
3233
auto message = tfm::format(fmt, args...);
3334
node::AbortNode(m_chain->context()->shutdown, m_chain->context()->exit_status, Untranslated(message), m_chain->context()->warnings.get());

src/index/base.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2022 The Bitcoin Core developers
1+
// Copyright (c) 2017-present The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -7,6 +7,7 @@
77

88
#include <dbwrapper.h>
99
#include <interfaces/chain.h>
10+
#include <util/string.h>
1011
#include <util/threadinterrupt.h>
1112
#include <validationinterface.h>
1213

@@ -94,7 +95,7 @@ class BaseIndex : public CValidationInterface
9495
virtual bool AllowPrune() const = 0;
9596

9697
template <typename... Args>
97-
void FatalErrorf(const char* fmt, const Args&... args);
98+
void FatalErrorf(util::ConstevalFormatString<sizeof...(Args)> fmt, const Args&... args);
9899

99100
protected:
100101
std::unique_ptr<interfaces::Chain> m_chain;

src/util/string.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define BITCOIN_UTIL_STRING_H
77

88
#include <span.h>
9+
#include <tinyformat.h>
910

1011
#include <array>
1112
#include <cstdint>
@@ -234,4 +235,12 @@ template <typename T1, size_t PREFIX_LEN>
234235
}
235236
} // namespace util
236237

238+
namespace tinyformat {
239+
template <typename... Args>
240+
std::string format(util::ConstevalFormatString<sizeof...(Args)> fmt, const Args&... args)
241+
{
242+
return format(fmt.fmt, args...);
243+
}
244+
} // namespace tinyformat
245+
237246
#endif // BITCOIN_UTIL_STRING_H

test/lint/lint-format-strings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import sys
1717

1818
FUNCTION_NAMES_AND_NUMBER_OF_LEADING_ARGUMENTS = [
19-
'FatalErrorf,0',
2019
'tfm::format,1', # Assuming tfm::::format(std::ostream&, ...
2120
'LogConnectFailure,1',
2221
'LogError,0',

test/lint/run-lint-format-strings.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import sys
1414

1515
FALSE_POSITIVES = [
16-
("src/index/base.cpp", "FatalErrorf(const char* fmt, const Args&... args)"),
17-
("src/index/base.h", "FatalErrorf(const char* fmt, const Args&... args)"),
1816
("src/netbase.cpp", "LogConnectFailure(bool manual_connection, const char* fmt, const Args&... args)"),
1917
("src/clientversion.cpp", "strprintf(_(COPYRIGHT_HOLDERS).translated, COPYRIGHT_HOLDERS_SUBSTITUTION)"),
2018
("src/test/translation_tests.cpp", "strprintf(format, arg)"),

0 commit comments

Comments
 (0)