More implicit truncation warning fixes
authorChristopher Dykes <cdykes@fb.com>
Fri, 16 Dec 2016 04:09:19 +0000 (20:09 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 16 Dec 2016 04:18:06 +0000 (20:18 -0800)
Summary:
This makes the changes required to compile Folly cleanly with the rest of MSVC's truncation warnings, 4244 & 4267.
Only another 2800 sign mismatch warnings left to go.

Reviewed By: yfeldblum

Differential Revision: D4257094

fbshipit-source-id: 1651eca875a31f53774d36c682f5e2745ddfcda5

33 files changed:
folly/Benchmark.cpp
folly/Benchmark.h
folly/Bits.h
folly/Checksum.cpp
folly/Conv.cpp
folly/Conv.h
folly/FBString.h
folly/FileUtil.cpp
folly/Format.cpp
folly/GroupVarint.h
folly/IndexedMemPool.h
folly/MPMCQueue.h
folly/MemoryMapping.cpp
folly/SparseByteSet.h
folly/SpookyHashV1.cpp
folly/SpookyHashV2.cpp
folly/String.cpp
folly/Uri.cpp
folly/Varint.h
folly/detail/CacheLocality.cpp
folly/detail/CacheLocality.h
folly/detail/MemoryIdler.h
folly/detail/RangeSse42.cpp
folly/detail/Stats.h
folly/detail/TurnSequencer.h
folly/experimental/FunctionScheduler.cpp
folly/experimental/JSONSchema.cpp
folly/fibers/EventBaseLoopController-inl.h
folly/io/RecordIO-inl.h
folly/io/RecordIO.cpp
folly/io/ShutdownSocketSet.cpp
folly/io/ShutdownSocketSet.h
folly/json.cpp

index 060c4bf4de0b3dbd489fa37cb716ca49c14371ba..ccae03448d064bebf3432e9e2f93ee9eeff4e5f8 100644 (file)
@@ -84,7 +84,7 @@ BENCHMARK(FB_FOLLY_GLOBAL_BENCHMARK_BASELINE) {
 #endif
 }
 
-int getGlobalBenchmarkBaselineIndex() {
+size_t getGlobalBenchmarkBaselineIndex() {
   const char *global = FB_STRINGIZE_X2(FB_FOLLY_GLOBAL_BENCHMARK_BASELINE);
   auto it = std::find_if(
     benchmarks().begin(),
@@ -94,7 +94,7 @@ int getGlobalBenchmarkBaselineIndex() {
     }
   );
   CHECK(it != benchmarks().end());
-  return it - benchmarks().begin();
+  return size_t(std::distance(benchmarks().begin(), it));
 }
 
 #undef FB_STRINGIZE_X2
@@ -465,7 +465,7 @@ void runBenchmarks() {
 
   // PLEASE KEEP QUIET. MEASUREMENTS IN PROGRESS.
 
-  unsigned int baselineIndex = getGlobalBenchmarkBaselineIndex();
+  size_t baselineIndex = getGlobalBenchmarkBaselineIndex();
 
   auto const globalBaseline =
       runBenchmarkGetNSPerIteration(get<2>(benchmarks()[baselineIndex]), 0);
index 4c1e2806de166b6de65629bed1bf8de277814ca5..0b193c658c254ceba705b8d3763995d68a5766a6 100644 (file)
@@ -116,7 +116,7 @@ struct BenchmarkSuspender {
   BenchmarkSuspender(const BenchmarkSuspender &) = delete;
   BenchmarkSuspender(BenchmarkSuspender && rhs) noexcept {
     start = rhs.start;
-    rhs.start.tv_nsec = rhs.start.tv_sec = 0;
+    rhs.start = {0, 0};
   }
 
   BenchmarkSuspender& operator=(const BenchmarkSuspender &) = delete;
@@ -125,7 +125,7 @@ struct BenchmarkSuspender {
       tally();
     }
     start = rhs.start;
-    rhs.start.tv_nsec = rhs.start.tv_sec = 0;
+    rhs.start = {0, 0};
     return *this;
   }
 
@@ -138,7 +138,7 @@ struct BenchmarkSuspender {
   void dismiss() {
     assert(start.tv_nsec > 0 || start.tv_sec > 0);
     tally();
-    start.tv_nsec = start.tv_sec = 0;
+    start = {0, 0};
   }
 
   void rehire() {
index 9742a06665fb6db6ef4394ccfb1f451b6bab76c9..6c794b12cd4082d391c6dff0a25d2f8faa220abb 100644 (file)
@@ -459,7 +459,7 @@ class BitIterator
       other.bitOffset_ - bitOffset_;
   }
 
-  unsigned int bitOffset_;
+  size_t bitOffset_;
 };
 
 /**
index c8dbec10c90061f9101c2825599c01a2782ead3a..49853bd408d5a2020e39065ba56f2d6aa4c18487 100644 (file)
@@ -52,7 +52,7 @@ uint32_t crc32c_hw(const uint8_t *data, size_t nbytes,
   // Process 8 bytes at a time until we have fewer than 8 bytes left.
   while (offset + sizeof(uint64_t) <= nbytes) {
     const uint64_t* src = (const uint64_t*)(data + offset);
-    sum = _mm_crc32_u64(sum, *src);
+    sum = uint32_t(_mm_crc32_u64(sum, *src));
     offset += sizeof(uint64_t);
   }
 
index 3e5214a879fa775ebcc424ea66a1332e9a1642f8..6571364614f2c943e0929d46b26b008643cce91e 100644 (file)
@@ -235,7 +235,7 @@ using IsAscii = std::
 // The code in this file that uses tolower() really only cares about
 // 7-bit ASCII characters, so we can take a nice shortcut here.
 inline char tolower_ascii(char in) {
-  return IsAscii::value ? in | 0x20 : std::tolower(in);
+  return IsAscii::value ? in | 0x20 : char(std::tolower(in));
 }
 
 inline bool bool_str_cmp(const char** b, size_t len, const char* value) {
@@ -365,7 +365,7 @@ Expected<Tgt, ConversionCode> str_to_floating(StringPiece* src) noexcept {
       return makeUnexpected(ConversionCode::EMPTY_INPUT_STRING);
     }
     src->advance(length);
-    return result;
+    return Tgt(result);
   }
 
   auto* e = src->end();
@@ -423,7 +423,7 @@ Expected<Tgt, ConversionCode> str_to_floating(StringPiece* src) noexcept {
 
   src->assign(b, e);
 
-  return result;
+  return Tgt(result);
 }
 
 template Expected<float, ConversionCode> str_to_floating<float>(
@@ -570,7 +570,7 @@ inline Expected<Tgt, ConversionCode> digits_to(
     if (sum >= OOR) {
       goto outOfRange;
     }
-    result = 1000 * result + sum;
+    result = UT(1000 * result + sum);
     break;
   }
   case 2: {
@@ -580,7 +580,7 @@ inline Expected<Tgt, ConversionCode> digits_to(
     if (sum >= OOR) {
       goto outOfRange;
     }
-    result = 100 * result + sum;
+    result = UT(100 * result + sum);
     break;
   }
   case 1: {
@@ -588,7 +588,7 @@ inline Expected<Tgt, ConversionCode> digits_to(
     if (sum >= OOR) {
       goto outOfRange;
     }
-    result = 10 * result + sum;
+    result = UT(10 * result + sum);
     break;
   }
   default:
index af2235e3d74b142a7382d04f07a46e4f8d6c51d6..37764d2434cfdb8725eafabb0c98aa520fe0d780 100644 (file)
@@ -383,12 +383,12 @@ inline uint32_t uint64ToBufferUnsafe(uint64_t v, char *const buffer) {
     // Keep these together so a peephole optimization "sees" them and
     // computes them in one shot.
     auto const q = v / 10;
-    auto const r = static_cast<uint32_t>(v % 10);
+    auto const r = static_cast<char>(v % 10);
     buffer[pos--] = '0' + r;
     v = q;
   }
   // Last digit is trivial to handle
-  buffer[pos] = static_cast<uint32_t>(v) + '0';
+  buffer[pos] = static_cast<char>(v) + '0';
   return result;
 }
 
index bb3d339b2f23b85ae9faf2b03b4461107c7475a7..7a9252d7aeef9a202350e747a9f650a6e729e574 100644 (file)
@@ -655,7 +655,7 @@ private:
     // small_[maxSmallSize].
     FBSTRING_ASSERT(s <= maxSmallSize);
     constexpr auto shift = kIsLittleEndian ? 0 : 2;
-    small_[maxSmallSize] = (maxSmallSize - s) << shift;
+    small_[maxSmallSize] = char((maxSmallSize - s) << shift);
     small_[s] = '\0';
     FBSTRING_ASSERT(category() == Category::isSmall && size() == s);
   }
index 70a8e095f7478e5d5635f80fc97afffd005e2fb6..0ec03b3cc6bfb4bb036c36c88ceecd385b860709 100644 (file)
@@ -29,7 +29,7 @@ namespace folly {
 using namespace fileutil_detail;
 
 int openNoInt(const char* name, int flags, mode_t mode) {
-  return wrapNoInt(open, name, flags, mode);
+  return int(wrapNoInt(open, name, flags, mode));
 }
 
 int closeNoInt(int fd) {
@@ -50,41 +50,41 @@ int closeNoInt(int fd) {
 }
 
 int fsyncNoInt(int fd) {
-  return wrapNoInt(fsync, fd);
+  return int(wrapNoInt(fsync, fd));
 }
 
 int dupNoInt(int fd) {
-  return wrapNoInt(dup, fd);
+  return int(wrapNoInt(dup, fd));
 }
 
 int dup2NoInt(int oldfd, int newfd) {
-  return wrapNoInt(dup2, oldfd, newfd);
+  return int(wrapNoInt(dup2, oldfd, newfd));
 }
 
 int fdatasyncNoInt(int fd) {
 #if defined(__APPLE__)
-  return wrapNoInt(fcntl, fd, F_FULLFSYNC);
+  return int(wrapNoInt(fcntl, fd, F_FULLFSYNC));
 #elif defined(__FreeBSD__) || defined(_MSC_VER)
-  return wrapNoInt(fsync, fd);
+  return int(wrapNoInt(fsync, fd));
 #else
-  return wrapNoInt(fdatasync, fd);
+  return int(wrapNoInt(fdatasync, fd));
 #endif
 }
 
 int ftruncateNoInt(int fd, off_t len) {
-  return wrapNoInt(ftruncate, fd, len);
+  return int(wrapNoInt(ftruncate, fd, len));
 }
 
 int truncateNoInt(const char* path, off_t len) {
-  return wrapNoInt(truncate, path, len);
+  return int(wrapNoInt(truncate, path, len));
 }
 
 int flockNoInt(int fd, int operation) {
-  return wrapNoInt(flock, fd, operation);
+  return int(wrapNoInt(flock, fd, operation));
 }
 
 int shutdownNoInt(int fd, int how) {
-  return wrapNoInt(portability::sockets::shutdown, fd, how);
+  return int(wrapNoInt(portability::sockets::shutdown, fd, how));
 }
 
 ssize_t readNoInt(int fd, void* buf, size_t count) {
index e6df11419f7dce100dc2113739da6089022c5535..3b11efe59ea6a897b2f2704e2d0957be295b36ab 100644 (file)
@@ -294,7 +294,7 @@ void FormatArg::validate(Type type) const {
 
 namespace detail {
 void insertThousandsGroupingUnsafe(char* start_buffer, char** end_buffer) {
-  uint32_t remaining_digits = *end_buffer - start_buffer;
+  uint32_t remaining_digits = uint32_t(*end_buffer - start_buffer);
   uint32_t separator_size = (remaining_digits - 1) / 3;
   uint32_t result_size = remaining_digits + separator_size;
   *end_buffer = *end_buffer + separator_size;
index 0e8f5edd74dc89544f54e3385cb1ffbd24e62b21..70a6fc3c3b2a90f4f6f1dc2a90509f9c96687798 100644 (file)
@@ -245,7 +245,7 @@ class GroupVarint<uint32_t> : public detail::GroupVarintBase<uint32_t> {
  private:
   static uint8_t key(uint32_t x) {
     // __builtin_clz is undefined for the x==0 case
-    return 3 - (__builtin_clz(x|1) / 8);
+    return uint8_t(3 - (__builtin_clz(x | 1) / 8));
   }
   static size_t b0key(size_t x) { return x & 3; }
   static size_t b1key(size_t x) { return (x >> 2) & 3; }
@@ -409,7 +409,7 @@ class GroupVarint<uint64_t> : public detail::GroupVarintBase<uint64_t> {
 
   static uint8_t key(uint64_t x) {
     // __builtin_clzll is undefined for the x==0 case
-    return 7 - (__builtin_clzll(x|1) / 8);
+    return uint8_t(7 - (__builtin_clzll(x | 1) / 8));
   }
 
   static uint8_t b0key(uint16_t x) { return x & 7; }
index bf35b559162e074b7b7ff7ba4e4e7daeb02712c5..d1723039b30ca16bbdc94137f2ed4941e2eca39c 100644 (file)
@@ -112,8 +112,9 @@ struct IndexedMemPool : boost::noncopyable {
 
   static constexpr uint32_t maxIndexForCapacity(uint32_t capacity) {
     // index of uint32_t(-1) == UINT32_MAX is reserved for isAllocated tracking
-    return std::min(uint64_t(capacity) + (NumLocalLists - 1) * LocalListLimit,
-                    uint64_t(uint32_t(-1) - 1));
+    return uint32_t(std::min(
+        uint64_t(capacity) + (NumLocalLists - 1) * LocalListLimit,
+        uint64_t(uint32_t(-1) - 1)));
   }
 
   static constexpr uint32_t capacityForMaxIndex(uint32_t maxIndex) {
@@ -217,7 +218,7 @@ struct IndexedMemPool : boost::noncopyable {
 
     auto slot = reinterpret_cast<const Slot*>(
         reinterpret_cast<const char*>(elem) - offsetof(Slot, elem));
-    auto rv = slot - slots_;
+    auto rv = uint32_t(slot - slots_);
 
     // this assert also tests that rv is in range
     assert(elem == &(*this)[rv]);
index e706a1f49eafb89744f9490c65af9e11ab2fe567..ce6e54a0b177aa71e2391a5289db23146e421bc4 100644 (file)
@@ -1067,7 +1067,7 @@ class MPMCQueueBase<Derived<T, Atom, Dynamic>> : boost::noncopyable {
   /// corresponding SingleElementQueue
   uint32_t turn(uint64_t ticket, size_t cap) noexcept {
     assert(cap != 0);
-    return ticket / cap;
+    return uint32_t(ticket / cap);
   }
 
   /// Tries to obtain a push ticket for which SingleElementQueue::enqueue
index 23fe52b29562bbec27385a3a60279bbe9836e299..d1f6997f1c4e92abcc9e4d009fc67ee8b24dcfa2 100644 (file)
@@ -129,7 +129,7 @@ void MemoryMapping::init(off_t offset, off_t length) {
   }
 
   if (pageSize == 0) {
-    pageSize = sysconf(_SC_PAGESIZE);
+    pageSize = off_t(sysconf(_SC_PAGESIZE));
   }
 
   CHECK_GT(pageSize, 0);
@@ -137,7 +137,7 @@ void MemoryMapping::init(off_t offset, off_t length) {
   CHECK_GE(offset, 0);
 
   // Round down the start of the mapped region
-  size_t skipStart = offset % pageSize;
+  off_t skipStart = offset % pageSize;
   offset -= skipStart;
 
   mapLength_ = length;
@@ -206,7 +206,7 @@ off_t memOpChunkSize(off_t length, off_t pageSize) {
     return chunkSize;
   }
 
-  chunkSize = FLAGS_mlock_chunk_size;
+  chunkSize = off_t(FLAGS_mlock_chunk_size);
   off_t r = chunkSize % pageSize;
   if (r) {
     chunkSize += (pageSize - r);
@@ -231,7 +231,7 @@ bool memOpInChunks(std::function<int(void*, size_t)> op,
   // chunks breaks the locking into intervals and lets other threads do memory
   // operations of their own.
 
-  size_t chunkSize = memOpChunkSize(bufSize, pageSize);
+  size_t chunkSize = memOpChunkSize(off_t(bufSize), pageSize);
 
   char* addr = static_cast<char*>(mem);
   amountSucceeded = 0;
@@ -377,7 +377,7 @@ void mmapFileCopy(const char* src, const char* dest, mode_t mode) {
   MemoryMapping destMap(
       File(dest, O_RDWR | O_CREAT | O_TRUNC, mode),
       0,
-      srcMap.range().size(),
+      off_t(srcMap.range().size()),
       MemoryMapping::writable());
 
   alignedForwardMemcpy(destMap.writableRange().data(),
index 2dc55e87f47554a884200e800d67a1b8a106f98d..05304daab7a49f5e49e74888cfb8c6e862035e56 100644 (file)
@@ -62,7 +62,7 @@ class SparseByteSet {
     if (r) {
       DCHECK_LT(size_, kCapacity);
       dense_[size_] = i;
-      sparse_[i] = size_;
+      sparse_[i] = uint8_t(size_);
       size_++;
     }
     return r;
index 9a13fca802dd05047075fa42b4697e62824f6914..ba6a91d187c29c86f487f52cc6ad0d3c09d4f7a7 100644 (file)
@@ -196,7 +196,7 @@ void SpookyHashV1::Hash128(
     remainder = (length - ((const uint8_t *)end-(const uint8_t *)message));
     memcpy(buf, end, remainder);
     memset(((uint8_t *)buf)+remainder, 0, sc_blockSize-remainder);
-    ((uint8_t *)buf)[sc_blockSize-1] = remainder;
+    ((uint8_t*)buf)[sc_blockSize - 1] = uint8_t(remainder);
     Mix(buf, h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
 
     // do some final mixing
index b945bc6f49badd6dafb63c6ab786b7fbb4ec8d52..cd251870efd20f983ec351f4939b2f6cf5610de6 100644 (file)
@@ -198,7 +198,7 @@ void SpookyHashV2::Hash128(
     remainder = (length - ((const uint8_t *)end-(const uint8_t *)message));
     memcpy(buf, end, remainder);
     memset(((uint8_t *)buf)+remainder, 0, sc_blockSize-remainder);
-    ((uint8_t *)buf)[sc_blockSize-1] = remainder;
+    ((uint8_t*)buf)[sc_blockSize - 1] = uint8_t(remainder);
 
     // do some final mixing
     End(buf, h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
index 94763881e8d2e36be0230322177137c2bd327ef7..06a7d968c6c29e512835ea64603ef4561641b5d8 100644 (file)
@@ -285,7 +285,7 @@ double prettyToDouble(folly::StringPiece *const prettyString,
         bestPrefixId = j;
       }
     } else if (prettyString->startsWith(suffixes[j].suffix)) {
-      int suffixLen = strlen(suffixes[j].suffix);
+      int suffixLen = int(strlen(suffixes[j].suffix));
       //We are looking for a longest suffix matching prefix of the string
       //after numeric value. We need this in case suffixes have common prefix.
       if (suffixLen > longestPrefixLen) {
index f278619b58c626eefcf19b8f105a3aa25c9ab76c..9a955b5420d3f5b0182b5c3aaf55b632334a5e60 100644 (file)
@@ -23,7 +23,7 @@ namespace folly {
 
 namespace {
 
-fbstring submatch(const boost::cmatch& m, size_t idx) {
+fbstring submatch(const boost::cmatch& m, int idx) {
   auto& sub = m[idx];
   return fbstring(sub.first, sub.second);
 }
index 859535736e764351cf32469473fb9a30bf010781..07968799f8a265cc3546de8cbcf5c556c2e70299 100644 (file)
@@ -87,7 +87,7 @@ inline size_t encodeVarint(uint64_t val, uint8_t* buf) {
     *p++ = 0x80 | (val & 0x7f);
     val >>= 7;
   }
-  *p++ = val;
+  *p++ = uint8_t(val);
   return p - buf;
 }
 
index c62e0ac8619cda5ce9d250f808319457b1dbc308..b514c60693b43ec58a48e7f383643bc8ed2d1322 100644 (file)
@@ -43,7 +43,7 @@ static CacheLocality getSystemLocalityInfo() {
   }
 #endif
 
-  long numCpus = sysconf(_SC_NPROCESSORS_CONF);
+  size_t numCpus = sysconf(_SC_NPROCESSORS_CONF);
   if (numCpus <= 0) {
     // This shouldn't happen, but if it does we should try to keep
     // going.  We are probably not going to be able to parse /sys on
@@ -156,7 +156,7 @@ CacheLocality CacheLocality::readFromSysfsTree(
               // a sub-optimal ordering, but it won't crash
               auto& lhsEquiv = equivClassesByCpu[lhs];
               auto& rhsEquiv = equivClassesByCpu[rhs];
-              for (int i = std::min(lhsEquiv.size(), rhsEquiv.size()) - 1;
+              for (int i = int(std::min(lhsEquiv.size(), rhsEquiv.size())) - 1;
                    i >= 0;
                    --i) {
                 if (lhsEquiv[i] != rhsEquiv[i]) {
index c9baf5281ac35afb97fd1aea184162a0ede740d0..bf043011d5aa73f5c3a98e8e3e85dc07bf047a90 100644 (file)
@@ -148,7 +148,7 @@ template <template <typename> class Atom>
 struct SequentialThreadId {
 
   /// Returns the thread id assigned to the current thread
-  static size_t get() {
+  static unsigned get() {
     auto rv = currentId;
     if (UNLIKELY(rv == 0)) {
       rv = currentId = ++prevId;
@@ -157,16 +157,16 @@ struct SequentialThreadId {
   }
 
  private:
-  static Atom<size_t> prevId;
+  static Atom<unsigned> prevId;
 
-  static FOLLY_TLS size_t currentId;
+  static FOLLY_TLS unsigned currentId;
 };
 
 template <template <typename> class Atom>
-Atom<size_t> SequentialThreadId<Atom>::prevId(0);
+Atom<unsigned> SequentialThreadId<Atom>::prevId(0);
 
 template <template <typename> class Atom>
-FOLLY_TLS size_t SequentialThreadId<Atom>::currentId(0);
+FOLLY_TLS unsigned SequentialThreadId<Atom>::currentId(0);
 
 // Suppress this instantiation in other translation units. It is
 // instantiated in CacheLocality.cpp
@@ -174,7 +174,7 @@ extern template struct SequentialThreadId<std::atomic>;
 #endif
 
 struct HashingThreadId {
-  static size_t get() {
+  static unsigned get() {
     pthread_t pid = pthread_self();
     uint64_t id = 0;
     memcpy(&id, &pid, std::min(sizeof(pid), sizeof(id)));
@@ -328,7 +328,8 @@ struct AccessSpreader {
         assert(index < n);
         // as index goes from 0..n, post-transform value goes from
         // 0..numStripes
-        widthAndCpuToStripe[width][cpu] = (index * numStripes) / n;
+        widthAndCpuToStripe[width][cpu] =
+            CompactStripe((index * numStripes) / n);
         assert(widthAndCpuToStripe[width][cpu] < numStripes);
       }
       for (size_t cpu = n; cpu < kMaxCpus; ++cpu) {
index bc155e91b88f930fb1c5eefb0b36a56e4ceb2436..13d4a4c4c231475df215ab23ed86ef4c91f9fbaa 100644 (file)
@@ -93,7 +93,7 @@ struct MemoryIdler {
       // multiplying the duration by a floating point doesn't work, grr..
       auto extraFrac =
         timeoutVariationFrac / std::numeric_limits<uint64_t>::max() * h;
-      uint64_t tics = idleTimeout.count() * (1 + extraFrac);
+      auto tics = uint64_t(idleTimeout.count() * (1 + extraFrac));
       idleTimeout = typename Clock::duration(tics);
     }
 
index 83ead386c5712aba00c28695ce6b9c619d26c190..4bd75be4647e5aa1d3a76b8a2887133eb941cb5f 100644 (file)
@@ -105,8 +105,8 @@ size_t qfind_first_byte_of_needles16(const StringPieceLite haystack,
   // do an unaligned load for first block of haystack
   auto arr1 = _mm_loadu_si128(
       reinterpret_cast<const __m128i*>(haystack.data()));
-  auto index = _mm_cmpestri(arr2, needles.size(),
-                            arr1, haystack.size(), 0);
+  auto index =
+      _mm_cmpestri(arr2, int(needles.size()), arr1, int(haystack.size()), 0);
   if (index < 16) {
     return index;
   }
@@ -116,7 +116,8 @@ size_t qfind_first_byte_of_needles16(const StringPieceLite haystack,
   for (; i < haystack.size(); i+= 16) {
     arr1 =
         _mm_load_si128(reinterpret_cast<const __m128i*>(haystack.data() + i));
-    index = _mm_cmpestri(arr2, needles.size(), arr1, haystack.size() - i, 0);
+    index = _mm_cmpestri(
+        arr2, int(needles.size()), arr1, int(haystack.size() - i), 0);
     if (index < 16) {
       return i + index;
     }
@@ -159,8 +160,8 @@ size_t scanHaystackBlock(const StringPieceLite haystack,
   // This load is safe because needles.size() >= 16
   auto arr2 = _mm_loadu_si128(
       reinterpret_cast<const __m128i*>(needles.data()));
-  size_t b = _mm_cmpestri(
-      arr2, 16, arr1, haystack.size() - blockStartIdx, 0);
+  size_t b =
+      _mm_cmpestri(arr2, 16, arr1, int(haystack.size() - blockStartIdx), 0);
 
   size_t j = nextAlignedIndex(needles.data());
   for (; j < needles.size(); j += 16) {
@@ -168,8 +169,11 @@ size_t scanHaystackBlock(const StringPieceLite haystack,
         reinterpret_cast<const __m128i*>(needles.data() + j));
 
     auto index = _mm_cmpestri(
-      arr2, needles.size() - j,
-      arr1, haystack.size() - blockStartIdx, 0);
+        arr2,
+        int(needles.size() - j),
+        arr1,
+        int(haystack.size() - blockStartIdx),
+        0);
     b = std::min<size_t>(index, b);
   }
 
index d99ac008055e9611019955c9fb449a558fc743dd..ad331d3b7b0ef6bb0fd96eacaf367724f97b290e 100644 (file)
@@ -44,8 +44,8 @@ typename std::enable_if<!std::is_same<typename std::remove_cv<ValueType>::type,
                         ReturnType>::type
 avgHelper(ValueType sum, uint64_t count) {
   if (count == 0) { return ReturnType(0); }
-  const double sumf = sum;
-  const double countf = count;
+  const double sumf = double(sum);
+  const double countf = double(count);
   return static_cast<ReturnType>(sumf / countf);
 }
 
index b70f258bf1d9780714c7bbfd53ec340ef161c032..536c2a493ae17eabde1c617f80e7c389ca054434 100644 (file)
@@ -215,7 +215,7 @@ struct TurnSequencer {
   /// Returns the least-most significant byte of the current uncompleted
   /// turn.  The full 32 bit turn cannot be recovered.
   uint8_t uncompletedTurnLSB() const noexcept {
-    return state_.load(std::memory_order_acquire) >> kTurnShift;
+    return uint8_t(state_.load(std::memory_order_acquire) >> kTurnShift);
   }
 
  private:
index 98bd9ed71e85c8d3b2b0bbbe30d82b3c4db49649..d2476c6ebbc3a659e1a8c7b5736bfe3ac12473b0 100644 (file)
@@ -63,7 +63,7 @@ struct PoissonDistributionFunctor {
 
 struct UniformDistributionFunctor {
   std::default_random_engine generator;
-  std::uniform_int_distribution<> dist;
+  std::uniform_int_distribution<milliseconds::rep> dist;
 
   UniformDistributionFunctor(milliseconds minInterval, milliseconds maxInterval)
       : generator(Random::rand32()),
index e2db5c450691f648cc1043079de1bcd15c3e30f4..d73d76b3c6ec5292aa6356d3502a6eadec7826fe 100644 (file)
@@ -616,7 +616,7 @@ struct AnyOfValidator final : IValidator {
         errors.emplace_back(*se);
       }
     }
-    const int success = validators_.size() - errors.size();
+    const auto success = validators_.size() - errors.size();
     if (success == 0) {
       return makeError("at least one valid schema", value);
     } else if (success > 1 && type_ == Type::EXACTLY_ONE) {
index b23fb45cd88c1d107b5055c2b94d41635abffba3..743177019534b10fd709e8d1944e3f0cc4f3797d 100644 (file)
@@ -118,8 +118,8 @@ inline void EventBaseLoopControllerT<EventBaseT>::timedSchedule(
           .count() +
       1;
   // If clock is not monotonic
-  delay_ms = std::max<decltype(delay_ms)>(delay_ms, 0L);
-  eventBase_->tryRunAfterDelay(func, delay_ms);
+  delay_ms = std::max<decltype(delay_ms)>(delay_ms, 0);
+  eventBase_->tryRunAfterDelay(func, uint32_t(delay_ms));
 }
 }
 } // folly::fibers
index 4eef3650886dd5d5b8135a1b620038da414eacd0..9638f580acc0dfeea58be97502df3dfe02b444a6 100644 (file)
@@ -37,7 +37,7 @@ class RecordIOReader::Iterator : public boost::iterator_facade<
   bool equal(const Iterator& other) const { return range_ == other.range_; }
   void increment() {
     size_t skip = recordio_helpers::headerSize() + recordAndPos_.first.size();
-    recordAndPos_.second += skip;
+    recordAndPos_.second += off_t(skip);
     range_.advance(skip);
     advanceToValid();
   }
index f279ae47e79863d17120f6259f6a0a78db755000..37efc51a8a979989bb1083165735c21edb206fc0 100644 (file)
@@ -54,7 +54,7 @@ void RecordIOWriter::write(std::unique_ptr<IOBuf> buf) {
   DCHECK_EQ(buf->computeChainDataLength(), totalLength);
 
   // We're going to write.  Reserve space for ourselves.
-  off_t pos = filePos_.fetch_add(totalLength);
+  off_t pos = filePos_.fetch_add(off_t(totalLength));
 
 #if FOLLY_HAVE_PWRITEV
   auto iov = buf->getIov();
@@ -100,7 +100,7 @@ void RecordIOReader::Iterator::advanceToValid() {
     skipped -= headerSize();
     range_.advance(skipped);
     recordAndPos_.first = record;
-    recordAndPos_.second += skipped;
+    recordAndPos_.second += off_t(skipped);
   }
 }
 
@@ -165,7 +165,7 @@ size_t prependHeader(std::unique_ptr<IOBuf>& buf, uint32_t fileId) {
   memset(header, 0, sizeof(Header));
   header->magic = detail::Header::kMagic;
   header->fileId = fileId;
-  header->dataLength = lengthAndHash.first;
+  header->dataLength = uint32_t(lengthAndHash.first);
   header->dataHash = lengthAndHash.second;
   header->headerHash = headerHash(*header);
 
index 9114c8f088b85fee77f474d3b48236a8e2f58407..215024e9e5a8fcd64ff08a6ba6648b4017ce81e7 100644 (file)
@@ -29,7 +29,7 @@
 
 namespace folly {
 
-ShutdownSocketSet::ShutdownSocketSet(size_t maxFd)
+ShutdownSocketSet::ShutdownSocketSet(int maxFd)
   : maxFd_(maxFd),
     data_(static_cast<std::atomic<uint8_t>*>(
             folly::checkedCalloc(maxFd, sizeof(std::atomic<uint8_t>)))),
@@ -39,7 +39,7 @@ ShutdownSocketSet::ShutdownSocketSet(size_t maxFd)
 void ShutdownSocketSet::add(int fd) {
   // Silently ignore any fds >= maxFd_, very unlikely
   DCHECK_GE(fd, 0);
-  if (size_t(fd) >= maxFd_) {
+  if (fd >= maxFd_) {
     return;
   }
 
@@ -53,7 +53,7 @@ void ShutdownSocketSet::add(int fd) {
 
 void ShutdownSocketSet::remove(int fd) {
   DCHECK_GE(fd, 0);
-  if (size_t(fd) >= maxFd_) {
+  if (fd >= maxFd_) {
     return;
   }
 
@@ -81,7 +81,7 @@ retry:
 
 int ShutdownSocketSet::close(int fd) {
   DCHECK_GE(fd, 0);
-  if (size_t(fd) >= maxFd_) {
+  if (fd >= maxFd_) {
     return folly::closeNoInt(fd);
   }
 
@@ -113,7 +113,7 @@ retry:
 
 void ShutdownSocketSet::shutdown(int fd, bool abortive) {
   DCHECK_GE(fd, 0);
-  if (fd >= 0 && size_t(fd) >= maxFd_) {
+  if (fd >= maxFd_) {
     doShutdown(fd, abortive);
     return;
   }
@@ -147,7 +147,7 @@ void ShutdownSocketSet::shutdown(int fd, bool abortive) {
 }
 
 void ShutdownSocketSet::shutdownAll(bool abortive) {
-  for (size_t i = 0; i < maxFd_; ++i) {
+  for (int i = 0; i < maxFd_; ++i) {
     auto& sref = data_[i];
     if (sref.load(std::memory_order_acquire) == IN_USE) {
       shutdown(i, abortive);
index c3beda32ab22abb1ad10aa7ff364c4ef36431513..17f1c050d3436c874e2078a08709f22ce68f2b44 100644 (file)
@@ -37,7 +37,7 @@ class ShutdownSocketSet : private boost::noncopyable {
    * applications, even if you increased the number of file descriptors
    * on your system.
    */
-  explicit ShutdownSocketSet(size_t maxFd = 1 << 18);
+  explicit ShutdownSocketSet(int maxFd = 1 << 18);
 
   /**
    * Add an already open socket to the list of sockets managed by
@@ -112,7 +112,7 @@ class ShutdownSocketSet : private boost::noncopyable {
     }
   };
 
-  const size_t maxFd_;
+  const int maxFd_;
   std::unique_ptr<std::atomic<uint8_t>[], Free> data_;
   folly::File nullFile_;
 };
index 0e6b01367764b855eade6c469aa81d151ddd3926..6e807229e2be2afed7e43586e46e421902f63c33 100644 (file)
@@ -553,10 +553,11 @@ dynamic parseNumber(Input& in) {
 
 std::string decodeUnicodeEscape(Input& in) {
   auto hexVal = [&] (int c) -> uint16_t {
-    return c >= '0' && c <= '9' ? c - '0' :
+    return uint16_t(
+           c >= '0' && c <= '9' ? c - '0' :
            c >= 'a' && c <= 'f' ? c - 'a' + 10 :
            c >= 'A' && c <= 'F' ? c - 'A' + 10 :
-           (in.error("invalid hex digit"), 0);
+           (in.error("invalid hex digit"), 0));
   };
 
   auto readHex = [&]() -> uint16_t {
@@ -689,7 +690,7 @@ void escapeString(
     StringPiece input,
     std::string& out,
     const serialization_opts& opts) {
-  auto hexDigit = [] (int c) -> char {
+  auto hexDigit = [] (uint8_t c) -> char {
     return c < 10 ? c + '0' : c - 10 + 'a';
   };
 
@@ -728,7 +729,7 @@ void escapeString(
       // with value > 127, so size > 1 byte
       char32_t v = decodeUtf8(p, e, opts.skip_invalid_utf8);
       out.append("\\u");
-      out.push_back(hexDigit(v >> 12));
+      out.push_back(hexDigit(uint8_t(v >> 12)));
       out.push_back(hexDigit((v >> 8) & 0x0f));
       out.push_back(hexDigit((v >> 4) & 0x0f));
       out.push_back(hexDigit(v & 0x0f));