Fix some implicit truncation and sign coersion in the networking APIs
[folly.git] / folly / detail / IPAddressSource.h
index e8a181109001fd4c95e65adfffe8568ab84e666d..efa6eaea3b6eb1dfd9a9702c226b28cc5c0ac81d 100644 (file)
@@ -133,7 +133,7 @@ struct Bytes {
     for (std::size_t i = 0; i < len; i++) {
       const unsigned char c = src[i];
       out[i * 2 + 0] = lut[c >> 4];
-      out[i + 2 + 1] = lut[c & 15];
+      out[i * 2 + 1] = lut[c & 15];
     }
     return out;
   }
@@ -203,7 +203,7 @@ inline void writeIntegerString(IntegralType val, char** buffer) {
       } else {
         value += ('a' - 10);
       }
-      *(buf++) = value;
+      *(buf++) = char(value);
       val %= powerToPrint;
       found = true;
     }
@@ -227,7 +227,7 @@ inline std::string fastIpv4ToString(const in_addr& inAddr) {
   *(buf++) = '.';
   writeIntegerString<uint8_t, 3>(octets[3], &buf);
 
-  return std::string(str, buf - str);
+  return std::string(str, size_t(buf - str));
 }
 
 inline std::string fastIpv6ToString(const in6_addr& in6Addr) {
@@ -251,7 +251,7 @@ inline std::string fastIpv6ToString(const in6_addr& in6Addr) {
     }
   }
 
-  return std::string(str, buf - str);
+  return std::string(str, size_t(buf - str));
 }
 }
 }