Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: Use C++11 member initialization in protocol #19020

Merged
merged 1 commit into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/compat/assumptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ static_assert(sizeof(double) == 8, "64-bit double assumed");
// code.
static_assert(sizeof(short) == 2, "16-bit short assumed");
static_assert(sizeof(int) == 4, "32-bit int assumed");
static_assert(sizeof(unsigned) == 4, "32-bit unsigned assumed");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't unsigned int be the value to test for equivalence?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsigned is a shorthand for unsigned int.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this check is redundant anyway, because prepending a type with unsigned shouldn't change it's bitlength. But I didn't feel like looking that up and adding the check has no downsides.


// Assumption: We assume size_t to be 32-bit or 64-bit.
// Example(s): size_t assumed to be at least 32-bit in ecdsa_signature_parse_der_lax(...).
Expand Down
18 changes: 0 additions & 18 deletions src/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,6 @@ void SetServiceFlagsIBDCache(bool state) {
g_initial_block_download_completed = state;
}


CAddress::CAddress() : CService()
{
Init();
}

CAddress::CAddress(CService ipIn, ServiceFlags nServicesIn) : CService(ipIn)
{
Init();
nServices = nServicesIn;
}

void CAddress::Init()
{
nServices = NODE_NONE;
nTime = 100000000;
}

CInv::CInv()
{
type = 0;
Expand Down
15 changes: 7 additions & 8 deletions src/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,15 @@ static inline bool MayHaveUsefulAddressDB(ServiceFlags services)
/** A CService with information about it as peer */
class CAddress : public CService
{
public:
CAddress();
explicit CAddress(CService ipIn, ServiceFlags nServicesIn);
static constexpr uint32_t TIME_INIT{100000000};

void Init();
public:
CAddress() : CService{} {};
explicit CAddress(CService ipIn, ServiceFlags nServicesIn) : CService{ipIn}, nServices{nServicesIn} {};

SERIALIZE_METHODS(CAddress, obj)
{
SER_READ(obj, obj.Init());
maflcko marked this conversation as resolved.
Show resolved Hide resolved
SER_READ(obj, obj.nTime = TIME_INIT);
int nVersion = s.GetVersion();
if (s.GetType() & SER_DISK) {
READWRITE(nVersion);
Expand All @@ -349,10 +349,9 @@ class CAddress : public CService
READWRITEAS(CService, obj);
}

ServiceFlags nServices;

ServiceFlags nServices{NODE_NONE};
// disk and network only
unsigned int nTime;
uint32_t nTime{TIME_INIT};
};

/** getdata message type flags */
Expand Down