Skip to content

Commit 3dd559d

Browse files
committed
Avoid static analyzer warnings regarding uninitialized arguments
- backports bitcoin/bitcoin@6835cb0 Avoid static analyzer warnings regarding "Function call argument is a pointer to uninitialized value" in cases where we are intentionally using such arguments. This is achieved by using ... `f(b.begin(), b.end())` (`std::array<char, N>`) ... instead of ... `f(b, b + N)` (`char b[N]`) Rationale: * Reduce false positives by guiding static analyzers regarding our intentions. Before this commit: ``` $ clang-tidy-3.5 -checks=* src/bench/base58.cpp bench/base58.cpp:23:9: warning: Function call argument is a pointer to uninitialized value [clang-analyzer-core.CallAndMessage] EncodeBase58(b, b + 32); ^ $ clang-tidy-3.5 -checks=* src/bench/verify_script.cpp bench/verify_script.cpp:59:5: warning: Function call argument is a pointer to uninitialized value [clang-analyzer-core.CallAndMessage] key.Set(vchKey, vchKey + 32, false); ^ $ ``` After this commit: ``` $ clang-tidy-3.5 -checks=* src/bench/base58.cpp $ clang-tidy-3.5 -checks=* src/bench/verify_script.cpp $ ```
1 parent e85f224 commit 3dd559d

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/bench/base58.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,30 @@
1313

1414
static void Base58Encode(benchmark::State& state)
1515
{
16-
unsigned char buff[32] = {
17-
17, 79, 8, 99, 150, 189, 208, 162, 22, 23, 203, 163, 36, 58, 147,
18-
227, 139, 2, 215, 100, 91, 38, 11, 141, 253, 40, 117, 21, 16, 90,
19-
200, 24
16+
static const std::array<unsigned char, 32> buff = {
17+
{
18+
17, 79, 8, 99, 150, 189, 208, 162, 22, 23, 203, 163, 36, 58, 147,
19+
227, 139, 2, 215, 100, 91, 38, 11, 141, 253, 40, 117, 21, 16, 90,
20+
200, 24
21+
}
2022
};
21-
unsigned char* b = buff;
2223
while (state.KeepRunning()) {
23-
EncodeBase58(b, b + 32);
24+
EncodeBase58(buff.begin(), buff.end());
2425
}
2526
}
2627

2728

2829
static void Base58CheckEncode(benchmark::State& state)
2930
{
30-
unsigned char buff[32] = {
31-
17, 79, 8, 99, 150, 189, 208, 162, 22, 23, 203, 163, 36, 58, 147,
32-
227, 139, 2, 215, 100, 91, 38, 11, 141, 253, 40, 117, 21, 16, 90,
33-
200, 24
31+
static const std::array<unsigned char, 32> buff = {
32+
{
33+
17, 79, 8, 99, 150, 189, 208, 162, 22, 23, 203, 163, 36, 58, 147,
34+
227, 139, 2, 215, 100, 91, 38, 11, 141, 253, 40, 117, 21, 16, 90,
35+
200, 24
36+
}
3437
};
35-
unsigned char* b = buff;
3638
std::vector<unsigned char> vch;
37-
vch.assign(b, b + 32);
39+
vch.assign(buff.begin(), buff.end());
3840
while (state.KeepRunning()) {
3941
EncodeBase58Check(vch);
4042
}

0 commit comments

Comments
 (0)