Skip to content

Commit cc3877f

Browse files
committed
Merge bitcoin/bitcoin#24971: tidy: modernize-use-nullptr
9c96f10 tidy: enable modernize-use-nullptr (fanquake) e532748 Don't use zero as null pointer constant (-Wzero-as-null-pointer-constant) (practicalswift) Pull request description: Alternative to #15112 which uses `clang-tidy` to do perform the checking, rather than `-Wzero-as-null-pointer-constant`, and avoids having to uses pragmas, i.e: ```cpp #if defined(HAVE_CONFIG_H) #include <config/bitcoin-config.h> #endif #if defined(HAVE_W_ZERO_AS_NULL_POINTER_CONSTANT) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" #pragma GCC diagnostic ignored "-Wunknown-pragmas" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" #endif ``` to suppress warnings coming from upstream code. Can be tested by dropping the preceding commit. Should produce errors like: ```bash clang-tidy-14 --use-color -p=/home/ubuntu/ci_scratch/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu /home/ubuntu/ci_scratch/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/src/netbase.cpp /home/ubuntu/ci_scratch/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/src/netbase.cpp:678:36: error: use nullptr [modernize-use-nullptr,-warnings-as-errors] if (!Socks5(strDest, port, 0, sock)) { ^ nullptr ``` ACKs for top commit: laanwj: Concept and code review ACK 9c96f10 Tree-SHA512: d822a354e44ba8f7fc53da9a4be7de5c25cc4ffc7c57651b76fdd1a030764b0390cfd79fca94685b8a3ff4f4d13054764f12d1f0d8c2a1b9ba519a7524f7f5bf
2 parents 23ebd7a + 9c96f10 commit cc3877f

File tree

12 files changed

+29
-13
lines changed

12 files changed

+29
-13
lines changed

ci/test/06_script_a.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ if [[ ${USE_MEMORY_SANITIZER} == "true" ]]; then
4949
fi
5050

5151
if [[ "${RUN_TIDY}" == "true" ]]; then
52-
MAYBE_BEAR="bear"
52+
MAYBE_BEAR="bear --config src/.bear-tidy-config"
5353
MAYBE_TOKEN="--"
5454
fi
5555

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,6 +1935,7 @@ AC_CONFIG_LINKS([contrib/devtools/test-security-check.py:contrib/devtools/test-s
19351935
AC_CONFIG_LINKS([contrib/devtools/test-symbol-check.py:contrib/devtools/test-symbol-check.py])
19361936
AC_CONFIG_LINKS([contrib/filter-lcov.py:contrib/filter-lcov.py])
19371937
AC_CONFIG_LINKS([contrib/macdeploy/background.tiff:contrib/macdeploy/background.tiff])
1938+
AC_CONFIG_LINKS([src/.bear-tidy-config:src/.bear-tidy-config])
19381939
AC_CONFIG_LINKS([src/.clang-tidy:src/.clang-tidy])
19391940
AC_CONFIG_LINKS([test/functional/test_runner.py:test/functional/test_runner.py])
19401941
AC_CONFIG_LINKS([test/fuzz/test_runner.py:test/fuzz/test_runner.py])

src/.bear-tidy-config

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"output": {
3+
"content": {
4+
"include_only_existing_source": true,
5+
"paths_to_include": [],
6+
"paths_to_exclude": [
7+
"src/leveldb"
8+
]
9+
},
10+
"format": {
11+
"command_as_array": true,
12+
"drop_output_field": false
13+
}
14+
}
15+
}

src/.clang-tidy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Checks: '-*,bugprone-argument-comment'
2-
WarningsAsErrors: bugprone-argument-comment
1+
Checks: '-*,bugprone-argument-comment,modernize-use-nullptr'
2+
WarningsAsErrors: 'bugprone-argument-comment,modernize-use-nullptr'

src/mapport.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static bool ProcessUpnp()
193193
std::string strDesc = PACKAGE_NAME " " + FormatFullVersion();
194194

195195
do {
196-
r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype, port.c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", 0, "0");
196+
r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype, port.c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", nullptr, "0");
197197

198198
if (r != UPNPCOMMAND_SUCCESS) {
199199
ret = false;
@@ -206,7 +206,7 @@ static bool ProcessUpnp()
206206
} while (g_mapport_interrupt.sleep_for(PORT_MAPPING_REANNOUNCE_PERIOD));
207207
g_mapport_interrupt.reset();
208208

209-
r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port.c_str(), "TCP", 0);
209+
r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port.c_str(), "TCP", nullptr);
210210
LogPrintf("UPNP_DeletePortMapping() returned: %d\n", r);
211211
freeUPNPDevlist(devlist); devlist = nullptr;
212212
FreeUPNPUrls(&urls);

src/netbase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ bool ConnectThroughProxy(const Proxy& proxy, const std::string& strDest, uint16_
675675
return false;
676676
}
677677
} else {
678-
if (!Socks5(strDest, port, 0, sock)) {
678+
if (!Socks5(strDest, port, nullptr, sock)) {
679679
return false;
680680
}
681681
}

src/qt/intro.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ bool Intro::showIfNeeded(bool& did_show_intro, int64_t& prune_MiB)
226226
}
227227

228228
/* If current default data directory does not exist, let the user choose one */
229-
Intro intro(0, Params().AssumedBlockchainSize(), Params().AssumedChainStateSize());
229+
Intro intro(nullptr, Params().AssumedBlockchainSize(), Params().AssumedChainStateSize());
230230
intro.setDataDirectory(dataDir);
231231
intro.setWindowIcon(QIcon(":icons/bitcoin"));
232232
did_show_intro = true;

src/randomenv.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,10 @@ void RandAddStaticEnv(CSHA512& hasher)
363363

364364
#if HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS
365365
// Network interfaces
366-
struct ifaddrs *ifad = NULL;
366+
struct ifaddrs *ifad = nullptr;
367367
getifaddrs(&ifad);
368368
struct ifaddrs *ifit = ifad;
369-
while (ifit != NULL) {
369+
while (ifit != nullptr) {
370370
hasher.Write((const unsigned char*)&ifit, sizeof(ifit));
371371
hasher.Write((const unsigned char*)ifit->ifa_name, strlen(ifit->ifa_name) + 1);
372372
hasher.Write((const unsigned char*)&ifit->ifa_flags, sizeof(ifit->ifa_flags));

src/support/allocators/secure.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct secure_allocator : public std::allocator<T> {
3737
typedef secure_allocator<_Other> other;
3838
};
3939

40-
T* allocate(std::size_t n, const void* hint = 0)
40+
T* allocate(std::size_t n, const void* hint = nullptr)
4141
{
4242
T* allocation = static_cast<T*>(LockedPoolManager::Instance().alloc(sizeof(T) * n));
4343
if (!allocation) {

src/test/fuzz/crypto_diff_fuzz_chacha20.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void ECRYPT_encrypt_bytes(ECRYPT_ctx* x, const u8* m, u8* c, u32 bytes)
128128
{
129129
u32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
130130
u32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
131-
u8* ctarget = NULL;
131+
u8* ctarget = nullptr;
132132
u8 tmp[64];
133133
uint32_t i;
134134

0 commit comments

Comments
 (0)