HDFS-9320. libhdfspp should use sizeof(int32_t) instead of sizeof(int) when parsing data. Contributed by James Clampffer.
This commit is contained in:
parent
5f1d0957b2
commit
a59714dcdb
|
@ -36,10 +36,10 @@ std::string Base64Encode(const std::string &src) {
|
|||
size_t i = 0;
|
||||
while (i + 3 < src.length()) {
|
||||
const char *s = &src[i];
|
||||
const int r[4] = {s[0] >> 2, ((s[0] << 4) | (s[1] >> 4)) & 0x3f,
|
||||
const int32_t r[4] = {s[0] >> 2, ((s[0] << 4) | (s[1] >> 4)) & 0x3f,
|
||||
((s[1] << 2) | (s[2] >> 6)) & 0x3f, s[2] & 0x3f};
|
||||
|
||||
std::transform(r, r + sizeof(r) / sizeof(int), std::back_inserter(dst),
|
||||
std::transform(r, r + sizeof(r) / sizeof(int32_t), std::back_inserter(dst),
|
||||
[&r](unsigned char v) { return kDictionary[v]; });
|
||||
i += 3;
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ private:
|
|||
}
|
||||
|
||||
size_t offset = 0, len = 0;
|
||||
for (size_t i = 0; i + 1 < transferred && i < sizeof(int); ++i) {
|
||||
for (size_t i = 0; i + 1 < transferred && i < sizeof(int32_t); ++i) {
|
||||
len = (len << 7) | (buf_[i] & 0x7f);
|
||||
if ((uint8_t)buf_.at(i) < 0x80) {
|
||||
offset = i + 1;
|
||||
|
|
|
@ -122,9 +122,9 @@ struct RemoteBlockReader<Stream>::ReadPacketHeader
|
|||
private:
|
||||
static const size_t kMaxHeaderSize = 512;
|
||||
static const size_t kPayloadLenOffset = 0;
|
||||
static const size_t kPayloadLenSize = sizeof(int);
|
||||
static const size_t kPayloadLenSize = sizeof(int32_t);
|
||||
static const size_t kHeaderLenOffset = 4;
|
||||
static const size_t kHeaderLenSize = sizeof(short);
|
||||
static const size_t kHeaderLenSize = sizeof(int16_t);
|
||||
static const size_t kHeaderStart = kPayloadLenSize + kHeaderLenSize;
|
||||
|
||||
RemoteBlockReader<Stream> *parent_;
|
||||
|
|
|
@ -82,8 +82,8 @@ ProducePacket(const std::string &data, const std::string &checksum,
|
|||
|
||||
char prefix[6];
|
||||
*reinterpret_cast<unsigned *>(prefix) =
|
||||
htonl(data.size() + checksum.size() + sizeof(int));
|
||||
*reinterpret_cast<short *>(prefix + sizeof(int)) = htons(proto.ByteSize());
|
||||
htonl(data.size() + checksum.size() + sizeof(int32_t));
|
||||
*reinterpret_cast<short *>(prefix + sizeof(int32_t)) = htons(proto.ByteSize());
|
||||
std::string payload(prefix, sizeof(prefix));
|
||||
payload.reserve(payload.size() + proto.ByteSize() + checksum.size() +
|
||||
data.size());
|
||||
|
|
Loading…
Reference in New Issue