Skip to content

Commit 00b828c

Browse files
laanwjPastaPastaPasta
authored andcommitted
Merge bitcoin#21939: refactor: Replace memset calls with array initialization
1c9255c refactor: Replace memset calls with array initialization (João Barbosa) Pull request description: Follow up to bitcoin#21905 (review). ACKs for top commit: laanwj: re-ACK 1c9255c Crypt-iQ: Code review ACK 1c9255c Tree-SHA512: 4b61dec2094f4781ef1c0427ee3bda3cfea12111274eebc7bc40a84f261d9c1681dd0860c57200bea2456588e44e8e0aecd18545c25f1f1250dd331ab7d05f28
1 parent 7bcc56c commit 00b828c

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

src/protocol.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,25 +202,16 @@ const static std::string netMessageTypesViolateBlocksOnly[] = {
202202
};
203203
const static std::set<std::string> netMessageTypesViolateBlocksOnlySet(std::begin(netMessageTypesViolateBlocksOnly), std::end(netMessageTypesViolateBlocksOnly));
204204

205-
CMessageHeader::CMessageHeader()
206-
{
207-
memset(pchMessageStart, 0, MESSAGE_START_SIZE);
208-
memset(pchCommand, 0, sizeof(pchCommand));
209-
memset(pchChecksum, 0, CHECKSUM_SIZE);
210-
}
211-
212205
CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn)
213206
{
214207
memcpy(pchMessageStart, pchMessageStartIn, MESSAGE_START_SIZE);
215208

216-
// Copy the command name, zero-padding to COMMAND_SIZE bytes
209+
// Copy the command name
217210
size_t i = 0;
218211
for (; i < COMMAND_SIZE && pszCommand[i] != 0; ++i) pchCommand[i] = pszCommand[i];
219212
assert(pszCommand[i] == 0); // Assert that the command name passed in is not longer than COMMAND_SIZE
220-
for (; i < COMMAND_SIZE; ++i) pchCommand[i] = 0;
221213

222214
nMessageSize = nMessageSizeIn;
223-
memset(pchChecksum, 0, CHECKSUM_SIZE);
224215
}
225216

226217
std::string CMessageHeader::GetCommand() const

src/protocol.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CMessageHeader
3939
static constexpr size_t HEADER_SIZE = MESSAGE_START_SIZE + COMMAND_SIZE + MESSAGE_SIZE_SIZE + CHECKSUM_SIZE;
4040
typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
4141

42-
explicit CMessageHeader();
42+
explicit CMessageHeader() = default;
4343

4444
/** Construct a P2P message header from message-start characters, a command and the size of the message.
4545
* @note Passing in a `pszCommand` longer than COMMAND_SIZE will result in a run-time assertion error.
@@ -51,10 +51,10 @@ class CMessageHeader
5151

5252
SERIALIZE_METHODS(CMessageHeader, obj) { READWRITE(obj.pchMessageStart, obj.pchCommand, obj.nMessageSize, obj.pchChecksum); }
5353

54-
char pchMessageStart[MESSAGE_START_SIZE];
55-
char pchCommand[COMMAND_SIZE];
54+
char pchMessageStart[MESSAGE_START_SIZE]{};
55+
char pchCommand[COMMAND_SIZE]{};
5656
uint32_t nMessageSize{std::numeric_limits<uint32_t>::max()};
57-
uint8_t pchChecksum[CHECKSUM_SIZE];
57+
uint8_t pchChecksum[CHECKSUM_SIZE]{};
5858
};
5959

6060
/**

0 commit comments

Comments
 (0)