Open
Description
paxoskv/msg_svr/msg_comm.cc
int total_len = *(reinterpret_cast<const int*>(buffer));
total_len = ntohl(total_len);
// ......
msg_size = total_len + sizeof(int);
const char* data = buffer + sizeof(int);
if (false == msg.ParseFromArray(data, msg_size - sizeof(int))) {
return BROKEN_PAXOS_MESSAGE;
}
在不同平台,int 所占的字节数不一定是4字节,使用 uint32_t 比 int 更好。改后代码。
uint32_t total_len = *(reinterpret_cast<const uint32_t*>(buffer));
total_len = ntohl(total_len);
// ......
msg_size = total_len + sizeof(uint32_t);
const char* data = buffer + sizeof(uint32_t);
if (false == msg.ParseFromArray(data, msg_size - sizeof(uint32_t))) {
return BROKEN_PAXOS_MESSAGE;
}
Metadata
Metadata
Assignees
Labels
No labels