Skip to content

Commit 2c74ad4

Browse files
committed
fix: adjust wallet/bip39 accordingly linter comments
1 parent d3faa85 commit 2c74ad4

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/wallet/bip39.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ SecureString CMnemonic::FromData(const SecureVector& data, int len)
6060
int mlen = len * 3 / 4;
6161
SecureString mnemonic;
6262

63-
int i, j, idx;
64-
for (i = 0; i < mlen; i++) {
65-
idx = 0;
66-
for (j = 0; j < 11; j++) {
63+
for (int i = 0; i < mlen; i++) {
64+
int idx = 0;
65+
for (int j = 0; j < 11; j++) {
6766
idx <<= 1;
6867
idx += (bits[(i * 11 + j) / 8] & (1 << (7 - ((i * 11 + j) % 8)))) > 0;
6968
}
@@ -76,7 +75,7 @@ SecureString CMnemonic::FromData(const SecureVector& data, int len)
7675
return mnemonic;
7776
}
7877

79-
bool CMnemonic::Check(SecureString mnemonic)
78+
bool CMnemonic::Check(const SecureString& mnemonic)
8079
{
8180
if (mnemonic.empty()) {
8281
return false;
@@ -98,7 +97,7 @@ bool CMnemonic::Check(SecureString mnemonic)
9897
SecureString ssCurrentWord;
9998
SecureVector bits(32 + 1);
10099

101-
uint32_t nWordIndex, ki, nBitsCount{};
100+
uint32_t ki, nBitsCount{};
102101

103102
for (size_t i = 0; i < mnemonic.size(); ++i)
104103
{
@@ -110,7 +109,7 @@ bool CMnemonic::Check(SecureString mnemonic)
110109
ssCurrentWord += mnemonic[i + ssCurrentWord.size()];
111110
}
112111
i += ssCurrentWord.size();
113-
nWordIndex = 0;
112+
uint32_t nWordIndex = 0;
114113
for (;;) {
115114
if (!wordlist[nWordIndex]) { // word not found
116115
return false;
@@ -140,7 +139,7 @@ bool CMnemonic::Check(SecureString mnemonic)
140139
}
141140

142141
// passphrase must be at most 256 characters otherwise it would be truncated
143-
void CMnemonic::ToSeed(SecureString mnemonic, SecureString passphrase, SecureVector& seedRet)
142+
void CMnemonic::ToSeed(const SecureString& mnemonic, const SecureString& passphrase, SecureVector& seedRet)
144143
{
145144
SecureString ssSalt = SecureString("mnemonic") + passphrase;
146145
SecureVector vchSalt(ssSalt.begin(), ssSalt.begin() + strnlen(ssSalt.data(), 256));

src/wallet/bip39.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class CMnemonic
3131
public:
3232
static SecureString Generate(int strength); // strength in bits
3333
static SecureString FromData(const SecureVector& data, int len);
34-
static bool Check(SecureString mnemonic);
34+
static bool Check(const SecureString& mnemonic);
3535
// passphrase must be at most 256 characters otherwise it would be truncated
36-
static void ToSeed(SecureString mnemonic, SecureString passphrase, SecureVector& seedRet);
36+
static void ToSeed(const SecureString& mnemonic, const SecureString& passphrase, SecureVector& seedRet);
3737
};
3838

3939
#endif // BITCOIN_WALLET_BIP39_H

test/lint/lint-cppcheck-dash.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ IGNORED_WARNINGS=(
3333
"src/llmq/commitment.cpp.* warning: Consider using std::all_of or std::none_of algorithm instead of a raw loop. \[useStlAlgorithm\]"
3434
"src/rpc/.*cpp:.*: note: Function pointer used here."
3535
"src/masternode/sync.cpp:.*: warning: Variable 'pnode' can be declared as pointer to const \[constVariableReference\]"
36+
"src/wallet/bip39.cpp.*: warning: The scope of the variable 'ssCurrentWord' can be reduced. \[variableScope\]"
37+
3638

3739
"src/stacktraces.cpp:.*: .*: Parameter 'info' can be declared as pointer to const"
3840
"src/stacktraces.cpp:.*: note: You might need to cast the function pointer here"

0 commit comments

Comments
 (0)