Skip to content

Commit 8d32af5

Browse files
authored
Merge pull request #2452 from barton2526/memset
refactor: Replace memset calls with array initialization
2 parents b49b102 + d42dc89 commit 8d32af5

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

src/protocol.cpp

+1-10
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,16 @@ static const char* ppszTypeName[] =
2121
"scraperindex",
2222
};
2323

24-
CMessageHeader::CMessageHeader()
25-
{
26-
memcpy(pchMessageStart, Params().MessageStart(), CMessageHeader::MESSAGE_START_SIZE);
27-
memset(pchCommand, 0, sizeof(pchCommand));
28-
memset(pchChecksum, 0, CHECKSUM_SIZE);
29-
}
30-
3124
CMessageHeader::CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn)
3225
{
3326
memcpy(pchMessageStart, Params().MessageStart(), CMessageHeader::MESSAGE_START_SIZE);
3427

35-
// Copy the command name, zero-padding to COMMAND_SIZE bytes
28+
// Copy the command name
3629
size_t i = 0;
3730
for (; i < COMMAND_SIZE && pszCommand[i] != 0; ++i) pchCommand[i] = pszCommand[i];
3831
assert(pszCommand[i] == 0); // Assert that the command name passed in is not longer than COMMAND_SIZE
39-
for (; i < COMMAND_SIZE; ++i) pchCommand[i] = 0;
4032

4133
nMessageSize = nMessageSizeIn;
42-
memset(pchChecksum, 0, CHECKSUM_SIZE);
4334
}
4435

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

src/protocol.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ class CMessageHeader
4343
static constexpr size_t HEADER_SIZE = MESSAGE_START_SIZE + COMMAND_SIZE + MESSAGE_SIZE_SIZE + CHECKSUM_SIZE;
4444
typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
4545

46-
CMessageHeader();
46+
CMessageHeader() = default;
4747
CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn);
4848

4949
std::string GetCommand() const;
5050
bool IsValid() const;
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
/** nServices flags */

0 commit comments

Comments
 (0)