Fix folly signed/unsigned comparisons
authorSean Cannella <seanc@fb.com>
Wed, 17 Sep 2014 00:08:52 +0000 (17:08 -0700)
committerDave Watson <davejwatson@fb.com>
Wed, 17 Sep 2014 18:23:46 +0000 (11:23 -0700)
Summary:
Fix a few sign comparison issues in folly::IPAddress

@override-unit-failures

Test Plan: existing tests, compiled with clang

Reviewed By: meyering@fb.com, davejwatson@fb.com

Subscribers: njormrod, bmatheny, subodh, ranjeeth, pgriess

FB internal diff: D1559152

folly/detail/IPAddress.h

index ba43bf0697b73de6e293685d26bcda2349f15565..f2552290ec80cb2ae83e8b43a48f4cb52f0aade1 100644 (file)
@@ -85,7 +85,7 @@ inline bool getNthMSBitImpl(const IPAddrType& ip, uint8_t bitIndex,
 struct Bytes : private boost::noncopyable {
   // return true if all values of src are zero
   static bool isZero(const uint8_t* src, std::size_t len) {
-    for (auto i = 0; i < len; i++) {
+    for (std::size_t i = 0; i < len; i++) {
       if (src[i] != 0x00) {
         return false;
       }
@@ -100,7 +100,7 @@ struct Bytes : private boost::noncopyable {
     static_assert(N > 0, "Can't mask an empty ByteArray");
     std::size_t asize = a.size();
     std::array<uint8_t, N> ba{{0}};
-    for (int i = 0; i < asize; i++) {
+    for (std::size_t i = 0; i < asize; i++) {
       ba[i] = a[i] & b[i];
     }
     return ba;
@@ -176,7 +176,7 @@ struct Bytes : private boost::noncopyable {
   static std::string toHex(const uint8_t* src, std::size_t len) {
     static const char* const lut = "0123456789abcdef";
     std::stringstream ss;
-    for (int i = 0; i < len; i++) {
+    for (std::size_t i = 0; i < len; i++) {
       const unsigned char c = src[i];
       ss << lut[c >> 4] << lut[c & 15];
     }