mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
net: Fail instead of truncate command name in CMessageHeader
Replace the memset/strncpy dance in `CMessageHeader::CMessageHeader` with explicit code that copies then name and asserts the length. This removes a warning in g++ 9.1.1 and IMO makes the code more readable by not relying on strncpy padding and silent truncation behavior.
This commit is contained in:
@@ -37,6 +37,10 @@ public:
|
||||
typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
|
||||
|
||||
explicit CMessageHeader(const MessageStartChars& pchMessageStartIn);
|
||||
|
||||
/** 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.
|
||||
*/
|
||||
CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn);
|
||||
|
||||
std::string GetCommand() const;
|
||||
|
||||
Reference in New Issue
Block a user