Skip to content

Commit d49d198

Browse files
committed
refactor: Initialize magic bytes in constructor initializer
Also remove an assert that is already enforced by the compiler checking that the length of the std::array matches.
1 parent 8243762 commit d49d198

File tree

3 files changed

+3
-6
lines changed

3 files changed

+3
-6
lines changed

src/net.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,10 +684,8 @@ bool CNode::ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete)
684684
}
685685

686686
V1Transport::V1Transport(const NodeId node_id, int nTypeIn, int nVersionIn) noexcept :
687-
m_node_id(node_id), hdrbuf(nTypeIn, nVersionIn), vRecv(nTypeIn, nVersionIn)
687+
m_magic_bytes{Params().MessageStart()}, m_node_id(node_id), hdrbuf(nTypeIn, nVersionIn), vRecv(nTypeIn, nVersionIn)
688688
{
689-
assert(std::size(Params().MessageStart()) == std::size(m_magic_bytes));
690-
m_magic_bytes = Params().MessageStart();
691689
LOCK(m_recv_mutex);
692690
Reset();
693691
}

src/net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ class Transport {
372372
class V1Transport final : public Transport
373373
{
374374
private:
375-
MessageStartChars m_magic_bytes;
375+
const MessageStartChars m_magic_bytes;
376376
const NodeId m_node_id; // Only for logging
377377
mutable Mutex m_recv_mutex; //!< Lock for receive state
378378
mutable CHash256 hasher GUARDED_BY(m_recv_mutex);

src/protocol.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ const static std::vector<std::string> g_all_net_message_types{
9191
};
9292

9393
CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn)
94+
: pchMessageStart{pchMessageStartIn}
9495
{
95-
pchMessageStart = pchMessageStartIn;
96-
9796
// Copy the command name
9897
size_t i = 0;
9998
for (; i < COMMAND_SIZE && pszCommand[i] != 0; ++i) pchCommand[i] = pszCommand[i];

0 commit comments

Comments
 (0)