diff options
| author | Wladimir J. van der Laan <[email protected]> | 2014-10-01 13:26:53 +0200 |
|---|---|---|
| committer | Wladimir J. van der Laan <[email protected]> | 2014-10-01 13:28:16 +0200 |
| commit | 1fbccda8d0d5ccfeef46e10253315c5c6977817c (patch) | |
| tree | 86f13328c0eff12d3e3b42ff9be39e078ae11b83 /src/protocol.cpp | |
| parent | Merge pull request #5023 (diff) | |
| parent | CMessageHeader sanity changes (diff) | |
| download | discoin-1fbccda8d0d5ccfeef46e10253315c5c6977817c.tar.xz discoin-1fbccda8d0d5ccfeef46e10253315c5c6977817c.zip | |
Merge pull request #4940
62e5f8f CMessageHeader sanity changes (Wladimir J. van der Laan)
Diffstat (limited to 'src/protocol.cpp')
| -rw-r--r-- | src/protocol.cpp | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/src/protocol.cpp b/src/protocol.cpp index 341de0602..0e28f3abb 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -24,7 +24,6 @@ CMessageHeader::CMessageHeader() { memcpy(pchMessageStart, Params().MessageStart(), MESSAGE_START_SIZE); memset(pchCommand, 0, sizeof(pchCommand)); - pchCommand[1] = 1; nMessageSize = -1; nChecksum = 0; } @@ -32,6 +31,7 @@ CMessageHeader::CMessageHeader() CMessageHeader::CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn) { memcpy(pchMessageStart, Params().MessageStart(), MESSAGE_START_SIZE); + memset(pchCommand, 0, sizeof(pchCommand)); strncpy(pchCommand, pszCommand, COMMAND_SIZE); nMessageSize = nMessageSizeIn; nChecksum = 0; @@ -39,10 +39,7 @@ CMessageHeader::CMessageHeader(const char* pszCommand, unsigned int nMessageSize std::string CMessageHeader::GetCommand() const { - if (pchCommand[COMMAND_SIZE-1] == 0) - return std::string(pchCommand, pchCommand + strlen(pchCommand)); - else - return std::string(pchCommand, pchCommand + COMMAND_SIZE); + return std::string(pchCommand, pchCommand + strnlen(pchCommand, COMMAND_SIZE)); } bool CMessageHeader::IsValid() const |