Browse Source

HDFS-9320. libhdfspp should use sizeof(int32_t) instead of sizeof(int) when parsing data. Contributed by James Clampffer.

Haohui Mai 9 năm trước cách đây
mục cha
commit
a59714dcdb

+ 2 - 2
hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/base64.cc

@@ -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;
   }

+ 1 - 1
hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/continuation/protobuf.h

@@ -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;

+ 2 - 2
hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/reader/remote_block_reader_impl.h

@@ -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_;

+ 2 - 2
hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/remote_block_reader_test.cc

@@ -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());