Skip to content

Commit

Permalink
Migrate last FLATDATA calls to use Span.
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Jul 3, 2021
1 parent 1ef2d90 commit fb3c646
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/addrdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ bool DeserializeDB(Stream& stream, Data& data, bool fCheckSum = true)
unsigned char pchMsgTmp[4];
verifier >> pchMsgTmp;
// ... verify the network matches ours
if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp)))
if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp)) != 0)
return error("%s: Invalid network magic number", __func__);

// de-serialize data
Expand Down
7 changes: 3 additions & 4 deletions src/budget/budgetdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ CBudgetDB::ReadResult CBudgetDB::Read(CBudgetManager& objToLoad, bool fDryRun)
}

int version;
unsigned char pchMsgTmp[4];
std::string strMagicMessageTmp;
try {
// de-serialize file header
Expand All @@ -106,12 +105,12 @@ CBudgetDB::ReadResult CBudgetDB::Read(CBudgetManager& objToLoad, bool fDryRun)
return IncorrectMagicMessage;
}


// de-serialize file header (network specific magic number) and ..
ssObj >> FLATDATA(pchMsgTmp);
std::vector<unsigned char> pchMsgTmp(4);
ssObj >> MakeSpan(pchMsgTmp);

// ... verify the network matches ours
if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp))) {
if (memcmp(pchMsgTmp.data(), Params().MessageStart(), pchMsgTmp.size()) != 0) {
error("%s : Invalid network magic number", __func__);
return IncorrectMagicNumber;
}
Expand Down
8 changes: 3 additions & 5 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include "masternode-payments.h"

#include "addrman.h"
#include "chainparams.h"
#include "evo/deterministicmns.h"
#include "fs.h"
Expand Down Expand Up @@ -112,7 +111,6 @@ CMasternodePaymentDB::ReadResult CMasternodePaymentDB::Read(CMasternodePayments&
}

int version;
unsigned char pchMsgTmp[4];
std::string strMagicMessageTmp;
try {
// de-serialize file header
Expand All @@ -125,12 +123,12 @@ CMasternodePaymentDB::ReadResult CMasternodePaymentDB::Read(CMasternodePayments&
return IncorrectMagicMessage;
}


// de-serialize file header (network specific magic number) and ..
ssObj >> FLATDATA(pchMsgTmp);
std::vector<unsigned char> pchMsgTmp(4);
ssObj >> MakeSpan(pchMsgTmp);

// ... verify the network matches ours
if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp))) {
if (memcmp(pchMsgTmp.data(), Params().MessageStart(), pchMsgTmp.size()) != 0) {
error("%s : Invalid network magic number", __func__);
return IncorrectMagicNumber;
}
Expand Down
6 changes: 3 additions & 3 deletions src/masternodeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ CMasternodeDB::ReadResult CMasternodeDB::Read(CMasternodeMan& mnodemanToLoad)
}

int version;
unsigned char pchMsgTmp[4];
std::string strMagicMessageTmp;
try {
// de-serialize file header
Expand All @@ -137,10 +136,11 @@ CMasternodeDB::ReadResult CMasternodeDB::Read(CMasternodeMan& mnodemanToLoad)
}

// de-serialize file header (network specific magic number) and ..
ssMasternodes >> FLATDATA(pchMsgTmp);
std::vector<unsigned char> pchMsgTmp(4);
ssMasternodes >> MakeSpan(pchMsgTmp);

// ... verify the network matches ours
if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp))) {
if (memcmp(pchMsgTmp.data(), Params().MessageStart(), pchMsgTmp.size()) != 0) {
error("%s : Invalid network magic number", __func__);
return IncorrectMagicNumber;
}
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class CKeyPool
READWRITE(vchPubKey);
if (ser_action.ForRead()) {
try {
READWRITE(FLATDATA(type));
READWRITE(Span<unsigned char>((unsigned char*)&type, 1));
READWRITE(m_pre_split);
} catch (std::ios_base::failure&) {
/* Set as external address if we can't read the type boolean
Expand All @@ -162,7 +162,7 @@ class CKeyPool
m_pre_split = true;
}
} else {
READWRITE(FLATDATA(type));
READWRITE(Span<unsigned char>((unsigned char*)&type, 1));
READWRITE(m_pre_split);
}
}
Expand Down

0 comments on commit fb3c646

Please sign in to comment.