diff options
author | W. J. van der Laan <laanwj@protonmail.com> | 2021-05-13 18:56:12 +0200 |
---|---|---|
committer | W. J. van der Laan <laanwj@protonmail.com> | 2021-05-13 19:25:21 +0200 |
commit | b34bf2b42caaee7c8714c1229e877128916d914a (patch) | |
tree | 21fc93bec3d44181a0067293772a2e7e1782ddb4 /src | |
parent | 4741aec1dd28829f45abcc529cddaa0ff04d07a0 (diff) | |
parent | 1c9255c7dd2d4f12bfb508bcc8d123a6354d8842 (diff) |
Merge bitcoin/bitcoin#21939: refactor: Replace memset calls with array initialization
1c9255c7dd2d4f12bfb508bcc8d123a6354d8842 refactor: Replace memset calls with array initialization (João Barbosa)
Pull request description:
Follow up to https://github.com/bitcoin/bitcoin/pull/21905#pullrequestreview-657045699.
ACKs for top commit:
laanwj:
re-ACK 1c9255c7dd2d4f12bfb508bcc8d123a6354d8842
Crypt-iQ:
Code review ACK 1c9255c7dd2d4f12bfb508bcc8d123a6354d8842
Tree-SHA512: 4b61dec2094f4781ef1c0427ee3bda3cfea12111274eebc7bc40a84f261d9c1681dd0860c57200bea2456588e44e8e0aecd18545c25f1f1250dd331ab7d05f28
Diffstat (limited to 'src')
-rw-r--r-- | src/protocol.cpp | 11 | ||||
-rw-r--r-- | src/protocol.h | 8 |
2 files changed, 5 insertions, 14 deletions
diff --git a/src/protocol.cpp b/src/protocol.cpp index 2f77ec18e6..2e70b41e4c 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -87,25 +87,16 @@ const static std::string allNetMessageTypes[] = { }; const static std::vector<std::string> allNetMessageTypesVec(std::begin(allNetMessageTypes), std::end(allNetMessageTypes)); -CMessageHeader::CMessageHeader() -{ - memset(pchMessageStart, 0, MESSAGE_START_SIZE); - memset(pchCommand, 0, sizeof(pchCommand)); - memset(pchChecksum, 0, CHECKSUM_SIZE); -} - CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn) { memcpy(pchMessageStart, pchMessageStartIn, MESSAGE_START_SIZE); - // Copy the command name, zero-padding to COMMAND_SIZE bytes + // Copy the command name size_t i = 0; for (; i < COMMAND_SIZE && pszCommand[i] != 0; ++i) pchCommand[i] = pszCommand[i]; assert(pszCommand[i] == 0); // Assert that the command name passed in is not longer than COMMAND_SIZE - for (; i < COMMAND_SIZE; ++i) pchCommand[i] = 0; nMessageSize = nMessageSizeIn; - memset(pchChecksum, 0, CHECKSUM_SIZE); } std::string CMessageHeader::GetCommand() const diff --git a/src/protocol.h b/src/protocol.h index c73484bdf6..aaa9f1df40 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -38,7 +38,7 @@ public: static constexpr size_t HEADER_SIZE = MESSAGE_START_SIZE + COMMAND_SIZE + MESSAGE_SIZE_SIZE + CHECKSUM_SIZE; typedef unsigned char MessageStartChars[MESSAGE_START_SIZE]; - explicit CMessageHeader(); + explicit CMessageHeader() = default; /** Construct a P2P message header from message-start characters, a command and the size of the message. * @note Passing in a `pszCommand` longer than COMMAND_SIZE will result in a run-time assertion error. @@ -50,10 +50,10 @@ public: SERIALIZE_METHODS(CMessageHeader, obj) { READWRITE(obj.pchMessageStart, obj.pchCommand, obj.nMessageSize, obj.pchChecksum); } - char pchMessageStart[MESSAGE_START_SIZE]; - char pchCommand[COMMAND_SIZE]; + char pchMessageStart[MESSAGE_START_SIZE]{}; + char pchCommand[COMMAND_SIZE]{}; uint32_t nMessageSize{std::numeric_limits<uint32_t>::max()}; - uint8_t pchChecksum[CHECKSUM_SIZE]; + uint8_t pchChecksum[CHECKSUM_SIZE]{}; }; /** |