Skip to content

Commit b8f59f6

Browse files
committed
Fix a pointer issue
1 parent 11f7e27 commit b8f59f6

21 files changed

+238
-155
lines changed

src/addrdb.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) 2009-2010 Satoshi Nakamoto
22
// Copyright (c) 2009-2016 The Bitcoin Core developers
3+
// Copyright (c) 2018 The BitZeny Core developers
34
// Distributed under the MIT software license, see the accompanying
45
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
56

@@ -23,8 +24,8 @@ bool SerializeDB(Stream& stream, const Data& data)
2324
// Write and commit header, data
2425
try {
2526
CHashWriter hasher(SER_DISK, CLIENT_VERSION);
26-
stream << FLATDATA(Params().MessageStart()) << data;
27-
hasher << FLATDATA(Params().MessageStart()) << data;
27+
stream << Params().MessageStart() << data;
28+
hasher << Params().MessageStart() << data;
2829
stream << hasher.GetHash();
2930
} catch (const std::exception& e) {
3031
return error("%s: Serialize or I/O error - %s", __func__, e.what());
@@ -67,7 +68,7 @@ bool DeserializeDB(Stream& stream, Data& data, bool fCheckSum = true)
6768
CHashVerifier<Stream> verifier(&stream);
6869
// de-serialize file header (network specific magic number) and ..
6970
unsigned char pchMsgTmp[4];
70-
verifier >> FLATDATA(pchMsgTmp);
71+
verifier >> pchMsgTmp;
7172
// ... verify the network matches ours
7273
if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp)))
7374
return error("%s: Invalid network magic number", __func__);

src/addrman.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) 2012 Pieter Wuille
22
// Copyright (c) 2012-2016 The Bitcoin Core developers
3+
// Copyright (c) 2018 The BitZeny Core developers
34
// Distributed under the MIT software license, see the accompanying
45
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
56

@@ -59,7 +60,7 @@ class CAddrInfo : public CAddress
5960

6061
template <typename Stream, typename Operation>
6162
inline void SerializationOp(Stream& s, Operation ser_action) {
62-
READWRITE(*(CAddress*)this);
63+
READWRITEAS(CAddress, *this);
6364
READWRITE(source);
6465
READWRITE(nLastSuccess);
6566
READWRITE(nAttempts);

src/blockencodings.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright (c) 2016 The Bitcoin Core developers
2+
// Copyright (c) 2018 The BitZeny Core developers
23
// Distributed under the MIT software license, see the accompanying
34
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
45

@@ -90,11 +91,11 @@ class BlockTransactions {
9091
while (txn.size() < txn_size) {
9192
txn.resize(std::min((uint64_t)(1000 + txn.size()), txn_size));
9293
for (; i < txn.size(); i++)
93-
READWRITE(REF(TransactionCompressor(txn[i])));
94+
READWRITE(TransactionCompressor(txn[i]));
9495
}
9596
} else {
9697
for (size_t i = 0; i < txn.size(); i++)
97-
READWRITE(REF(TransactionCompressor(txn[i])));
98+
READWRITE(TransactionCompressor(txn[i]));
9899
}
99100
}
100101
};
@@ -115,7 +116,7 @@ struct PrefilledTransaction {
115116
if (idx > std::numeric_limits<uint16_t>::max())
116117
throw std::ios_base::failure("index overflowed 16-bits");
117118
index = idx;
118-
READWRITE(REF(TransactionCompressor(tx)));
119+
READWRITE(TransactionCompressor(tx));
119120
}
120121
};
121122

src/coins.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) 2009-2010 Satoshi Nakamoto
22
// Copyright (c) 2009-2016 The Bitcoin Core developers
3+
// Copyright (c) 2018 The BitZeny Core developers
34
// Distributed under the MIT software license, see the accompanying
45
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
56

@@ -69,7 +70,7 @@ class Coin
6970
::Unserialize(s, VARINT(code));
7071
nHeight = code >> 1;
7172
fCoinBase = code & 1;
72-
::Unserialize(s, REF(CTxOutCompressor(out)));
73+
::Unserialize(s, CTxOutCompressor(out));
7374
}
7475

7576
bool IsSpent() const {

src/compressor.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) 2009-2010 Satoshi Nakamoto
22
// Copyright (c) 2009-2016 The Bitcoin Core developers
3+
// Copyright (c) 2018 The BitZeny Core developers
34
// Distributed under the MIT software license, see the accompanying
45
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
56

@@ -9,6 +10,7 @@
910
#include "primitives/transaction.h"
1011
#include "script/script.h"
1112
#include "serialize.h"
13+
#include "span.h"
1214

1315
class CKeyID;
1416
class CPubKey;
@@ -59,12 +61,12 @@ class CScriptCompressor
5961
void Serialize(Stream &s) const {
6062
std::vector<unsigned char> compr;
6163
if (Compress(compr)) {
62-
s << CFlatData(compr);
64+
s << MakeSpan(compr);
6365
return;
6466
}
6567
unsigned int nSize = script.size() + nSpecialScripts;
6668
s << VARINT(nSize);
67-
s << CFlatData(script);
69+
s << MakeSpan(script);
6870
}
6971

7072
template<typename Stream>
@@ -73,7 +75,7 @@ class CScriptCompressor
7375
s >> VARINT(nSize);
7476
if (nSize < nSpecialScripts) {
7577
std::vector<unsigned char> vch(GetSpecialSize(nSize), 0x00);
76-
s >> REF(CFlatData(vch));
78+
s >> MakeSpan(vch);
7779
Decompress(nSize, vch);
7880
return;
7981
}
@@ -84,7 +86,7 @@ class CScriptCompressor
8486
s.ignore(nSize);
8587
} else {
8688
script.resize(nSize);
87-
s >> REF(CFlatData(script));
89+
s >> MakeSpan(script);
8890
}
8991
}
9092
};

src/hash.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) 2009-2010 Satoshi Nakamoto
22
// Copyright (c) 2009-2016 The Bitcoin Core developers
3+
// Copyright (c) 2018 The BitZeny Core developers
34
// Distributed under the MIT software license, see the accompanying
45
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
56

@@ -187,7 +188,7 @@ class CHashVerifier : public CHashWriter
187188
}
188189

189190
template<typename T>
190-
CHashVerifier<Source>& operator>>(T& obj)
191+
CHashVerifier<Source>& operator>>(T&& obj)
191192
{
192193
// Unserialize from this stream
193194
::Unserialize(*this, obj);

src/netaddress.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright (c) 2009-2016 The Bitcoin Core developers
2+
// Copyright (c) 2018 The BitZeny Core developers
23
// Distributed under the MIT software license, see the accompanying
34
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
45

@@ -11,6 +12,7 @@
1112

1213
#include "compat.h"
1314
#include "serialize.h"
15+
#include "span.h"
1416

1517
#include <stdint.h>
1618
#include <string>
@@ -93,7 +95,7 @@ class CNetAddr
9395

9496
template <typename Stream, typename Operation>
9597
inline void SerializationOp(Stream& s, Operation ser_action) {
96-
READWRITE(FLATDATA(ip));
98+
READWRITE(ip);
9799
}
98100

99101
friend class CSubNet;
@@ -131,16 +133,16 @@ class CSubNet
131133
template <typename Stream, typename Operation>
132134
inline void SerializationOp(Stream& s, Operation ser_action) {
133135
READWRITE(network);
134-
READWRITE(FLATDATA(netmask));
135-
READWRITE(FLATDATA(valid));
136+
READWRITE(netmask);
137+
READWRITE(valid);
136138
}
137139
};
138140

139141
/** A combination of a network address (CNetAddr) and a (TCP) port */
140142
class CService : public CNetAddr
141143
{
142144
protected:
143-
unsigned short port; // host order
145+
uint16_t port; // host order
144146

145147
public:
146148
CService();
@@ -166,11 +168,8 @@ class CService : public CNetAddr
166168

167169
template <typename Stream, typename Operation>
168170
inline void SerializationOp(Stream& s, Operation ser_action) {
169-
READWRITE(FLATDATA(ip));
170-
unsigned short portN = htons(port);
171-
READWRITE(FLATDATA(portN));
172-
if (ser_action.ForRead())
173-
port = ntohs(portN);
171+
READWRITE(ip);
172+
READWRITE(WrapBigEndian(port));
174173
}
175174
};
176175

src/primitives/block.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) 2009-2010 Satoshi Nakamoto
22
// Copyright (c) 2009-2016 The Bitcoin Core developers
3+
// Copyright (c) 2018 The BitZeny Core developers
34
// Distributed under the MIT software license, see the accompanying
45
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
56

@@ -93,7 +94,7 @@ class CBlock : public CBlockHeader
9394

9495
template <typename Stream, typename Operation>
9596
inline void SerializationOp(Stream& s, Operation ser_action) {
96-
READWRITE(*(CBlockHeader*)this);
97+
READWRITEAS(CBlockHeader, *this);
9798
READWRITE(vtx);
9899
}
99100

src/protocol.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) 2009-2010 Satoshi Nakamoto
22
// Copyright (c) 2009-2016 The Bitcoin Core developers
3+
// Copyright (c) 2018 The BitZeny Core developers
34
// Distributed under the MIT software license, see the accompanying
45
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
56

@@ -50,10 +51,10 @@ class CMessageHeader
5051
template <typename Stream, typename Operation>
5152
inline void SerializationOp(Stream& s, Operation ser_action)
5253
{
53-
READWRITE(FLATDATA(pchMessageStart));
54-
READWRITE(FLATDATA(pchCommand));
54+
READWRITE(pchMessageStart);
55+
READWRITE(pchCommand);
5556
READWRITE(nMessageSize);
56-
READWRITE(FLATDATA(pchChecksum));
57+
READWRITE(pchChecksum);
5758
}
5859

5960
char pchMessageStart[MESSAGE_START_SIZE];
@@ -302,7 +303,7 @@ class CAddress : public CService
302303
uint64_t nServicesInt = nServices;
303304
READWRITE(nServicesInt);
304305
nServices = (ServiceFlags)nServicesInt;
305-
READWRITE(*(CService*)this);
306+
READWRITEAS(CService, *this);
306307
}
307308

308309
// TODO: make private (improves encapsulation)

src/script/bitcoinconsensus.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) 2009-2010 Satoshi Nakamoto
22
// Copyright (c) 2009-2016 The Bitcoin Core developers
3+
// Copyright (c) 2018 The BitZeny Core developers
34
// Distributed under the MIT software license, see the accompanying
45
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
56

@@ -40,7 +41,7 @@ class TxInputStream
4041
}
4142

4243
template<typename T>
43-
TxInputStream& operator>>(T& obj)
44+
TxInputStream& operator>>(T&& obj)
4445
{
4546
::Unserialize(*this, obj);
4647
return *this;

src/script/script.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) 2009-2010 Satoshi Nakamoto
22
// Copyright (c) 2009-2016 The Bitcoin Core developers
3+
// Copyright (c) 2018 The BitZeny Core developers
34
// Distributed under the MIT software license, see the accompanying
45
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
56

@@ -409,7 +410,7 @@ class CScript : public CScriptBase
409410

410411
template <typename Stream, typename Operation>
411412
inline void SerializationOp(Stream& s, Operation ser_action) {
412-
READWRITE(static_cast<CScriptBase&>(*this));
413+
READWRITEAS(CScriptBase, *this);
413414
}
414415

415416
CScript& operator+=(const CScript& b)

0 commit comments

Comments
 (0)