Skip to content

Commit efb4383

Browse files
committed
Merge #10793: Changing &var[0] to var.data()
592404f Changing &vec[0] to vec.data(), what 9804 missed (MeshCollider) Pull request description: This just continues the work of bitcoin/bitcoin#9804 Modifies a lot of `&vector[]`'s to `vector.data()`'s across all the files including tests, just the stuff that 9804 missed Tree-SHA512: dd1a9dffb999dea4fba78dcc91fe02f90250db86f5c74948e1ff3e8b4036b2154b600555eaa04dece5368920aae3513bc36425dc96e4319ca1041b0928a6b656
2 parents 723e580 + 592404f commit efb4383

15 files changed

+48
-49
lines changed

src/bench/crypto_hash.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static void SHA256_32b(benchmark::State& state)
4747
std::vector<uint8_t> in(32,0);
4848
while (state.KeepRunning()) {
4949
for (int i = 0; i < 1000000; i++) {
50-
CSHA256().Write(in.data(), in.size()).Finalize(&in[0]);
50+
CSHA256().Write(in.data(), in.size()).Finalize(in.data());
5151
}
5252
}
5353
}

src/qt/signverifymessagedialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void SignVerifyMessageDialog::on_signMessageButton_SM_clicked()
162162
ui->statusLabel_SM->setStyleSheet("QLabel { color: green; }");
163163
ui->statusLabel_SM->setText(QString("<nobr>") + tr("Message signed.") + QString("</nobr>"));
164164

165-
ui->signatureOut_SM->setText(QString::fromStdString(EncodeBase64(&vchSig[0], vchSig.size())));
165+
ui->signatureOut_SM->setText(QString::fromStdString(EncodeBase64(vchSig.data(), vchSig.size())));
166166
}
167167

168168
void SignVerifyMessageDialog::on_copySignatureButton_SM_clicked()

src/qt/test/paymentservertests.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ X509 *parse_b64der_cert(const char* cert_data)
2424
{
2525
std::vector<unsigned char> data = DecodeBase64(cert_data);
2626
assert(data.size() > 0);
27-
const unsigned char* dptr = &data[0];
27+
const unsigned char* dptr = data.data();
2828
X509 *cert = d2i_X509(nullptr, &dptr, data.size());
2929
assert(cert);
3030
return cert;
@@ -43,7 +43,7 @@ static SendCoinsRecipient handleRequest(PaymentServer* server, std::vector<unsig
4343
// Write data to a temp file:
4444
QTemporaryFile f;
4545
f.open();
46-
f.write((const char*)&data[0], data.size());
46+
f.write((const char*)data.data(), data.size());
4747
f.close();
4848

4949
// Create a QObject, install event filter from PaymentServer
@@ -139,7 +139,7 @@ void PaymentServerTests::paymentServerTests()
139139

140140
// Contains a testnet paytoaddress, so payment request network doesn't match client network:
141141
data = DecodeBase64(paymentrequest1_cert2_BASE64);
142-
byteArray = QByteArray((const char*)&data[0], data.size());
142+
byteArray = QByteArray((const char*)data.data(), data.size());
143143
r.paymentRequest.parse(byteArray);
144144
// Ensure the request is initialized, because network "main" is default, even for
145145
// uninitialized payment requests and that will fail our test here.
@@ -148,7 +148,7 @@ void PaymentServerTests::paymentServerTests()
148148

149149
// Expired payment request (expires is set to 1 = 1970-01-01 00:00:01):
150150
data = DecodeBase64(paymentrequest2_cert2_BASE64);
151-
byteArray = QByteArray((const char*)&data[0], data.size());
151+
byteArray = QByteArray((const char*)data.data(), data.size());
152152
r.paymentRequest.parse(byteArray);
153153
// Ensure the request is initialized
154154
QVERIFY(r.paymentRequest.IsInitialized());
@@ -159,7 +159,7 @@ void PaymentServerTests::paymentServerTests()
159159
// 9223372036854775807 (uint64), 9223372036854775807 (int64_t) and -1 (int32_t)
160160
// -1 is 1969-12-31 23:59:59 (for a 32 bit time values)
161161
data = DecodeBase64(paymentrequest3_cert2_BASE64);
162-
byteArray = QByteArray((const char*)&data[0], data.size());
162+
byteArray = QByteArray((const char*)data.data(), data.size());
163163
r.paymentRequest.parse(byteArray);
164164
// Ensure the request is initialized
165165
QVERIFY(r.paymentRequest.IsInitialized());
@@ -170,7 +170,7 @@ void PaymentServerTests::paymentServerTests()
170170
// 9223372036854775808 (uint64), -9223372036854775808 (int64_t) and 0 (int32_t)
171171
// 0 is 1970-01-01 00:00:00 (for a 32 bit time values)
172172
data = DecodeBase64(paymentrequest4_cert2_BASE64);
173-
byteArray = QByteArray((const char*)&data[0], data.size());
173+
byteArray = QByteArray((const char*)data.data(), data.size());
174174
r.paymentRequest.parse(byteArray);
175175
// Ensure the request is initialized
176176
QVERIFY(r.paymentRequest.IsInitialized());
@@ -190,7 +190,7 @@ void PaymentServerTests::paymentServerTests()
190190

191191
// Payment request with amount overflow (amount is set to 21000001 BTC):
192192
data = DecodeBase64(paymentrequest5_cert2_BASE64);
193-
byteArray = QByteArray((const char*)&data[0], data.size());
193+
byteArray = QByteArray((const char*)data.data(), data.size());
194194
r.paymentRequest.parse(byteArray);
195195
// Ensure the request is initialized
196196
QVERIFY(r.paymentRequest.IsInitialized());

src/rpc/misc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ UniValue signmessagewithprivkey(const JSONRPCRequest& request)
371371
if (!key.SignCompact(ss.GetHash(), vchSig))
372372
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed");
373373

374-
return EncodeBase64(&vchSig[0], vchSig.size());
374+
return EncodeBase64(vchSig.data(), vchSig.size());
375375
}
376376

377377
UniValue setmocktime(const JSONRPCRequest& request)

src/script/interpreter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,7 @@ static bool VerifyWitnessProgram(const CScriptWitness& witness, int witversion,
13661366
stack = std::vector<std::vector<unsigned char> >(witness.stack.begin(), witness.stack.end() - 1);
13671367
uint256 hashScriptPubKey;
13681368
CSHA256().Write(&scriptPubKey[0], scriptPubKey.size()).Finalize(hashScriptPubKey.begin());
1369-
if (memcmp(hashScriptPubKey.begin(), &program[0], 32)) {
1369+
if (memcmp(hashScriptPubKey.begin(), program.data(), 32)) {
13701370
return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH);
13711371
}
13721372
} else if (program.size() == 20) {

src/test/bip32_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void RunTest(const TestVector &test) {
9191
std::vector<unsigned char> seed = ParseHex(test.strHexMaster);
9292
CExtKey key;
9393
CExtPubKey pubkey;
94-
key.SetMaster(&seed[0], seed.size());
94+
key.SetMaster(seed.data(), seed.size());
9595
pubkey = key.Neuter();
9696
for (const TestDerivation &derive : test.vDerive) {
9797
unsigned char data[74];

src/test/bloom_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ BOOST_AUTO_TEST_CASE(bloom_match)
154154
COutPoint prevOutPoint(uint256S("0x90c122d70786e899529d71dbeba91ba216982fb6ba58f3bdaab65e73b7e9260b"), 0);
155155
{
156156
std::vector<unsigned char> data(32 + sizeof(unsigned int));
157-
memcpy(&data[0], prevOutPoint.hash.begin(), 32);
158-
memcpy(&data[32], &prevOutPoint.n, sizeof(unsigned int));
157+
memcpy(data.data(), prevOutPoint.hash.begin(), 32);
158+
memcpy(data.data()+32, &prevOutPoint.n, sizeof(unsigned int));
159159
filter.insert(data);
160160
}
161161
BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match manually serialized COutPoint");

src/test/crypto_tests.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ void TestRIPEMD160(const std::string &in, const std::string &hexout) { TestVecto
5858

5959
void TestHMACSHA256(const std::string &hexkey, const std::string &hexin, const std::string &hexout) {
6060
std::vector<unsigned char> key = ParseHex(hexkey);
61-
TestVector(CHMAC_SHA256(&key[0], key.size()), ParseHex(hexin), ParseHex(hexout));
61+
TestVector(CHMAC_SHA256(key.data(), key.size()), ParseHex(hexin), ParseHex(hexout));
6262
}
6363

6464
void TestHMACSHA512(const std::string &hexkey, const std::string &hexin, const std::string &hexout) {
6565
std::vector<unsigned char> key = ParseHex(hexkey);
66-
TestVector(CHMAC_SHA512(&key[0], key.size()), ParseHex(hexin), ParseHex(hexout));
66+
TestVector(CHMAC_SHA512(key.data(), key.size()), ParseHex(hexin), ParseHex(hexout));
6767
}
6868

6969
void TestAES128(const std::string &hexkey, const std::string &hexin, const std::string &hexout)
@@ -76,13 +76,13 @@ void TestAES128(const std::string &hexkey, const std::string &hexin, const std::
7676
assert(key.size() == 16);
7777
assert(in.size() == 16);
7878
assert(correctout.size() == 16);
79-
AES128Encrypt enc(&key[0]);
79+
AES128Encrypt enc(key.data());
8080
buf.resize(correctout.size());
8181
buf2.resize(correctout.size());
82-
enc.Encrypt(&buf[0], &in[0]);
82+
enc.Encrypt(buf.data(), in.data());
8383
BOOST_CHECK_EQUAL(HexStr(buf), HexStr(correctout));
84-
AES128Decrypt dec(&key[0]);
85-
dec.Decrypt(&buf2[0], &buf[0]);
84+
AES128Decrypt dec(key.data());
85+
dec.Decrypt(buf2.data(), buf.data());
8686
BOOST_CHECK_EQUAL(HexStr(buf2), HexStr(in));
8787
}
8888

@@ -96,12 +96,12 @@ void TestAES256(const std::string &hexkey, const std::string &hexin, const std::
9696
assert(key.size() == 32);
9797
assert(in.size() == 16);
9898
assert(correctout.size() == 16);
99-
AES256Encrypt enc(&key[0]);
99+
AES256Encrypt enc(key.data());
100100
buf.resize(correctout.size());
101-
enc.Encrypt(&buf[0], &in[0]);
101+
enc.Encrypt(buf.data(), in.data());
102102
BOOST_CHECK(buf == correctout);
103-
AES256Decrypt dec(&key[0]);
104-
dec.Decrypt(&buf[0], &buf[0]);
103+
AES256Decrypt dec(key.data());
104+
dec.Decrypt(buf.data(), buf.data());
105105
BOOST_CHECK(buf == in);
106106
}
107107

@@ -114,16 +114,16 @@ void TestAES128CBC(const std::string &hexkey, const std::string &hexiv, bool pad
114114
std::vector<unsigned char> realout(in.size() + AES_BLOCKSIZE);
115115

116116
// Encrypt the plaintext and verify that it equals the cipher
117-
AES128CBCEncrypt enc(&key[0], &iv[0], pad);
118-
int size = enc.Encrypt(&in[0], in.size(), &realout[0]);
117+
AES128CBCEncrypt enc(key.data(), iv.data(), pad);
118+
int size = enc.Encrypt(in.data(), in.size(), realout.data());
119119
realout.resize(size);
120120
BOOST_CHECK(realout.size() == correctout.size());
121121
BOOST_CHECK_MESSAGE(realout == correctout, HexStr(realout) + std::string(" != ") + hexout);
122122

123123
// Decrypt the cipher and verify that it equals the plaintext
124124
std::vector<unsigned char> decrypted(correctout.size());
125-
AES128CBCDecrypt dec(&key[0], &iv[0], pad);
126-
size = dec.Decrypt(&correctout[0], correctout.size(), &decrypted[0]);
125+
AES128CBCDecrypt dec(key.data(), iv.data(), pad);
126+
size = dec.Decrypt(correctout.data(), correctout.size(), decrypted.data());
127127
decrypted.resize(size);
128128
BOOST_CHECK(decrypted.size() == in.size());
129129
BOOST_CHECK_MESSAGE(decrypted == in, HexStr(decrypted) + std::string(" != ") + hexin);
@@ -133,12 +133,12 @@ void TestAES128CBC(const std::string &hexkey, const std::string &hexiv, bool pad
133133
{
134134
std::vector<unsigned char> sub(i, in.end());
135135
std::vector<unsigned char> subout(sub.size() + AES_BLOCKSIZE);
136-
int _size = enc.Encrypt(&sub[0], sub.size(), &subout[0]);
136+
int _size = enc.Encrypt(sub.data(), sub.size(), subout.data());
137137
if (_size != 0)
138138
{
139139
subout.resize(_size);
140140
std::vector<unsigned char> subdecrypted(subout.size());
141-
_size = dec.Decrypt(&subout[0], subout.size(), &subdecrypted[0]);
141+
_size = dec.Decrypt(subout.data(), subout.size(), subdecrypted.data());
142142
subdecrypted.resize(_size);
143143
BOOST_CHECK(decrypted.size() == in.size());
144144
BOOST_CHECK_MESSAGE(subdecrypted == sub, HexStr(subdecrypted) + std::string(" != ") + HexStr(sub));
@@ -155,16 +155,16 @@ void TestAES256CBC(const std::string &hexkey, const std::string &hexiv, bool pad
155155
std::vector<unsigned char> realout(in.size() + AES_BLOCKSIZE);
156156

157157
// Encrypt the plaintext and verify that it equals the cipher
158-
AES256CBCEncrypt enc(&key[0], &iv[0], pad);
159-
int size = enc.Encrypt(&in[0], in.size(), &realout[0]);
158+
AES256CBCEncrypt enc(key.data(), iv.data(), pad);
159+
int size = enc.Encrypt(in.data(), in.size(), realout.data());
160160
realout.resize(size);
161161
BOOST_CHECK(realout.size() == correctout.size());
162162
BOOST_CHECK_MESSAGE(realout == correctout, HexStr(realout) + std::string(" != ") + hexout);
163163

164164
// Decrypt the cipher and verify that it equals the plaintext
165165
std::vector<unsigned char> decrypted(correctout.size());
166-
AES256CBCDecrypt dec(&key[0], &iv[0], pad);
167-
size = dec.Decrypt(&correctout[0], correctout.size(), &decrypted[0]);
166+
AES256CBCDecrypt dec(key.data(), iv.data(), pad);
167+
size = dec.Decrypt(correctout.data(), correctout.size(), decrypted.data());
168168
decrypted.resize(size);
169169
BOOST_CHECK(decrypted.size() == in.size());
170170
BOOST_CHECK_MESSAGE(decrypted == in, HexStr(decrypted) + std::string(" != ") + hexin);
@@ -174,12 +174,12 @@ void TestAES256CBC(const std::string &hexkey, const std::string &hexiv, bool pad
174174
{
175175
std::vector<unsigned char> sub(i, in.end());
176176
std::vector<unsigned char> subout(sub.size() + AES_BLOCKSIZE);
177-
int _size = enc.Encrypt(&sub[0], sub.size(), &subout[0]);
177+
int _size = enc.Encrypt(sub.data(), sub.size(), subout.data());
178178
if (_size != 0)
179179
{
180180
subout.resize(_size);
181181
std::vector<unsigned char> subdecrypted(subout.size());
182-
_size = dec.Decrypt(&subout[0], subout.size(), &subdecrypted[0]);
182+
_size = dec.Decrypt(subout.data(), subout.size(), subdecrypted.data());
183183
subdecrypted.resize(_size);
184184
BOOST_CHECK(decrypted.size() == in.size());
185185
BOOST_CHECK_MESSAGE(subdecrypted == sub, HexStr(subdecrypted) + std::string(" != ") + HexStr(sub));

src/test/getarg_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static void ResetArgs(const std::string& strArg)
2727
for (std::string& s : vecArg)
2828
vecChar.push_back(s.c_str());
2929

30-
gArgs.ParseParameters(vecChar.size(), &vecChar[0]);
30+
gArgs.ParseParameters(vecChar.size(), vecChar.data());
3131
}
3232

3333
BOOST_AUTO_TEST_CASE(boolarg)

src/test/skiplist_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ BOOST_AUTO_TEST_CASE(skiplist_test)
3939

4040
BOOST_CHECK(vIndex[SKIPLIST_LENGTH - 1].GetAncestor(from) == &vIndex[from]);
4141
BOOST_CHECK(vIndex[from].GetAncestor(to) == &vIndex[to]);
42-
BOOST_CHECK(vIndex[from].GetAncestor(0) == &vIndex[0]);
42+
BOOST_CHECK(vIndex[from].GetAncestor(0) == vIndex.data());
4343
}
4444
}
4545

@@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE(getlocator_test)
6464
for (unsigned int i=0; i<vBlocksSide.size(); i++) {
6565
vHashSide[i] = ArithToUint256(i + 50000 + (arith_uint256(1) << 128)); // Add 1<<128 to the hashes, so GetLow64() still returns the height.
6666
vBlocksSide[i].nHeight = i + 50000;
67-
vBlocksSide[i].pprev = i ? &vBlocksSide[i - 1] : &vBlocksMain[49999];
67+
vBlocksSide[i].pprev = i ? &vBlocksSide[i - 1] : (vBlocksMain.data()+49999);
6868
vBlocksSide[i].phashBlock = &vHashSide[i];
6969
vBlocksSide[i].BuildSkip();
7070
BOOST_CHECK_EQUAL((int)UintToArith256(vBlocksSide[i].GetBlockHash()).GetLow64(), vBlocksSide[i].nHeight);

0 commit comments

Comments
 (0)