Skip to content

Commit fac30ee

Browse files
author
MarcoFalke
committed
refactor: Replace &foo[0] with foo.data()
1 parent faece47 commit fac30ee

File tree

15 files changed

+40
-40
lines changed

15 files changed

+40
-40
lines changed

build_msvc/testconsensus/testconsensus.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ int main()
4545
stream << vanillaSpendTx;
4646

4747
bitcoinconsensus_error err;
48-
auto op0Result = bitcoinconsensus_verify_script_with_amount(pubKeyScript.data(), pubKeyScript.size(), amount, (const unsigned char*)&stream[0], stream.size(), 0, bitcoinconsensus_SCRIPT_FLAGS_VERIFY_ALL, &err);
48+
auto op0Result = bitcoinconsensus_verify_script_with_amount(pubKeyScript.data(), pubKeyScript.size(), amount, stream.data(), stream.size(), 0, bitcoinconsensus_SCRIPT_FLAGS_VERIFY_ALL, &err);
4949
std::cout << "Op0 result: " << op0Result << ", error code " << err << std::endl;
5050

5151
getchar();

src/qt/walletmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &tran
248248

249249
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
250250
ssTx << *newTx;
251-
transaction_array.append((const char*)&(ssTx[0]), ssTx.size());
251+
transaction_array.append((const char*)ssTx.data(), ssTx.size());
252252
}
253253

254254
// Add addresses / update labels that we've sent to the address book,

src/random.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ std::vector<unsigned char> FastRandomContext::randbytes(size_t len)
628628
if (requires_seed) RandomSeed();
629629
std::vector<unsigned char> ret(len);
630630
if (len > 0) {
631-
rng.Keystream(&ret[0], len);
631+
rng.Keystream(ret.data(), len);
632632
}
633633
return ret;
634634
}

src/script/interpreter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ static bool VerifyWitnessProgram(const CScriptWitness& witness, int witversion,
18901890
const valtype& script_bytes = SpanPopBack(stack);
18911891
exec_script = CScript(script_bytes.begin(), script_bytes.end());
18921892
uint256 hash_exec_script;
1893-
CSHA256().Write(&exec_script[0], exec_script.size()).Finalize(hash_exec_script.begin());
1893+
CSHA256().Write(exec_script.data(), exec_script.size()).Finalize(hash_exec_script.begin());
18941894
if (memcmp(hash_exec_script.begin(), program.data(), 32)) {
18951895
return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH);
18961896
}

src/script/sigcache.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ class CSignatureCache
5353
ComputeEntryECDSA(uint256& entry, const uint256 &hash, const std::vector<unsigned char>& vchSig, const CPubKey& pubkey) const
5454
{
5555
CSHA256 hasher = m_salted_hasher_ecdsa;
56-
hasher.Write(hash.begin(), 32).Write(&pubkey[0], pubkey.size()).Write(vchSig.data(), vchSig.size()).Finalize(entry.begin());
56+
hasher.Write(hash.begin(), 32).Write(pubkey.data(), pubkey.size()).Write(vchSig.data(), vchSig.size()).Finalize(entry.begin());
5757
}
5858

5959
void
6060
ComputeEntrySchnorr(uint256& entry, const uint256 &hash, Span<const unsigned char> sig, const XOnlyPubKey& pubkey) const
6161
{
6262
CSHA256 hasher = m_salted_hasher_schnorr;
63-
hasher.Write(hash.begin(), 32).Write(&pubkey[0], pubkey.size()).Write(sig.data(), sig.size()).Finalize(entry.begin());
63+
hasher.Write(hash.begin(), 32).Write(pubkey.data(), pubkey.size()).Write(sig.data(), sig.size()).Finalize(entry.begin());
6464
}
6565

6666
bool

src/script/sign.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ static bool SignStep(const SigningProvider& provider, const BaseSignatureCreator
167167
return true;
168168

169169
case TxoutType::WITNESS_V0_SCRIPTHASH:
170-
CRIPEMD160().Write(&vSolutions[0][0], vSolutions[0].size()).Finalize(h160.begin());
170+
CRIPEMD160().Write(vSolutions[0].data(), vSolutions[0].size()).Finalize(h160.begin());
171171
if (GetCScript(provider, sigdata, CScriptID{h160}, scriptRet)) {
172172
ret.push_back(std::vector<unsigned char>(scriptRet.begin(), scriptRet.end()));
173173
return true;

src/test/compress_tests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE(compress_script_to_ckey_id)
7979
// Check compressed script
8080
BOOST_CHECK_EQUAL(out.size(), 21U);
8181
BOOST_CHECK_EQUAL(out[0], 0x00);
82-
BOOST_CHECK_EQUAL(memcmp(&out[1], &script[3], 20), 0); // compare the 20 relevant chars of the CKeyId in the script
82+
BOOST_CHECK_EQUAL(memcmp(out.data() + 1, script.data() + 3, 20), 0); // compare the 20 relevant chars of the CKeyId in the script
8383
}
8484

8585
BOOST_AUTO_TEST_CASE(compress_script_to_cscript_id)
@@ -96,7 +96,7 @@ BOOST_AUTO_TEST_CASE(compress_script_to_cscript_id)
9696
// Check compressed script
9797
BOOST_CHECK_EQUAL(out.size(), 21U);
9898
BOOST_CHECK_EQUAL(out[0], 0x01);
99-
BOOST_CHECK_EQUAL(memcmp(&out[1], &script[2], 20), 0); // compare the 20 relevant chars of the CScriptId in the script
99+
BOOST_CHECK_EQUAL(memcmp(out.data() + 1, script.data() + 2, 20), 0); // compare the 20 relevant chars of the CScriptId in the script
100100
}
101101

102102
BOOST_AUTO_TEST_CASE(compress_script_to_compressed_pubkey_id)
@@ -113,8 +113,8 @@ BOOST_AUTO_TEST_CASE(compress_script_to_compressed_pubkey_id)
113113

114114
// Check compressed script
115115
BOOST_CHECK_EQUAL(out.size(), 33U);
116-
BOOST_CHECK_EQUAL(memcmp(&out[0], &script[1], 1), 0);
117-
BOOST_CHECK_EQUAL(memcmp(&out[1], &script[2], 32), 0); // compare the 32 chars of the compressed CPubKey
116+
BOOST_CHECK_EQUAL(memcmp(out.data(), script.data() + 1, 1), 0);
117+
BOOST_CHECK_EQUAL(memcmp(out.data() + 1, script.data() + 2, 32), 0); // compare the 32 chars of the compressed CPubKey
118118
}
119119

120120
BOOST_AUTO_TEST_CASE(compress_script_to_uncompressed_pubkey_id)
@@ -130,7 +130,7 @@ BOOST_AUTO_TEST_CASE(compress_script_to_uncompressed_pubkey_id)
130130

131131
// Check compressed script
132132
BOOST_CHECK_EQUAL(out.size(), 33U);
133-
BOOST_CHECK_EQUAL(memcmp(&out[1], &script[2], 32), 0); // first 32 chars of CPubKey are copied into out[1:]
133+
BOOST_CHECK_EQUAL(memcmp(out.data() + 1, script.data() + 2, 32), 0); // first 32 chars of CPubKey are copied into out[1:]
134134
BOOST_CHECK_EQUAL(out[0], 0x04 | (script[65] & 0x01)); // least significant bit (lsb) of last char of pubkey is mapped into out[0]
135135
}
136136

src/test/crypto_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static void TestVector(const Hasher &h, const In &in, const Out &out) {
3333
hash.resize(out.size());
3434
{
3535
// Test that writing the whole input string at once works.
36-
Hasher(h).Write((unsigned char*)&in[0], in.size()).Finalize(&hash[0]);
36+
Hasher(h).Write((const uint8_t*)in.data(), in.size()).Finalize(hash.data());
3737
BOOST_CHECK(hash == out);
3838
}
3939
for (int i=0; i<32; i++) {
@@ -42,15 +42,15 @@ static void TestVector(const Hasher &h, const In &in, const Out &out) {
4242
size_t pos = 0;
4343
while (pos < in.size()) {
4444
size_t len = InsecureRandRange((in.size() - pos + 1) / 2 + 1);
45-
hasher.Write((unsigned char*)&in[pos], len);
45+
hasher.Write((const uint8_t*)in.data() + pos, len);
4646
pos += len;
4747
if (pos > 0 && pos + 2 * out.size() > in.size() && pos < in.size()) {
4848
// Test that writing the rest at once to a copy of a hasher works.
49-
Hasher(hasher).Write((unsigned char*)&in[pos], in.size() - pos).Finalize(&hash[0]);
49+
Hasher(hasher).Write((const uint8_t*)in.data() + pos, in.size() - pos).Finalize(hash.data());
5050
BOOST_CHECK(hash == out);
5151
}
5252
}
53-
hasher.Finalize(&hash[0]);
53+
hasher.Finalize(hash.data());
5454
BOOST_CHECK(hash == out);
5555
}
5656
}

src/test/fuzz/util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ CScript ConsumeScript(FuzzedDataProvider& fuzzed_data_provider, const size_t max
273273
CScript r_script{b.begin(), b.end()};
274274
if (maybe_p2wsh && fuzzed_data_provider.ConsumeBool()) {
275275
uint256 script_hash;
276-
CSHA256().Write(&r_script[0], r_script.size()).Finalize(script_hash.begin());
276+
CSHA256().Write(r_script.data(), r_script.size()).Finalize(script_hash.begin());
277277
r_script.clear();
278278
r_script << OP_0 << ToByteVector(script_hash);
279279
}

src/test/script_standard_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(script_standard_Solver_success)
9898

9999
// TxoutType::WITNESS_V0_SCRIPTHASH
100100
uint256 scriptHash;
101-
CSHA256().Write(&redeemScript[0], redeemScript.size())
101+
CSHA256().Write(redeemScript.data(), redeemScript.size())
102102
.Finalize(scriptHash.begin());
103103

104104
s.clear();
@@ -370,7 +370,7 @@ BOOST_AUTO_TEST_CASE(script_standard_GetScriptFor_)
370370
witnessScript << OP_1 << ToByteVector(pubkeys[0]) << OP_1 << OP_CHECKMULTISIG;
371371

372372
uint256 scriptHash;
373-
CSHA256().Write(&witnessScript[0], witnessScript.size())
373+
CSHA256().Write(witnessScript.data(), witnessScript.size())
374374
.Finalize(scriptHash.begin());
375375

376376
expected.clear();

0 commit comments

Comments
 (0)