Fixing a -Wshorten-64-32 issues in folly for liger.
authorKyle Dent <kmdent@fb.com>
Wed, 28 Jan 2015 19:33:49 +0000 (11:33 -0800)
committerwoo <woo@fb.com>
Mon, 2 Feb 2015 21:13:12 +0000 (13:13 -0800)
Summary: Normally I would use the folly::to<> function, but it would cause a circular dependency, so I just added a static cast

Test Plan: Ran on iOS and ran the folly tests

Reviewed By: seanc@fb.com

Subscribers: lucian, mpawlowski, marcelo, tudorb, aalexandre, seanc, folly-diffs@

FB internal diff: D1806632

Signature: t1:1806632:1422416646:b8104f18f90eb7457f2f358428f2bd800f8f1db5

folly/Range.h

index f22d30e9418461e9085884ad0dd977e1b75698e0..2ce83f8d6d0f068e25b7c3e0ebcd6e1d9f947132 100644 (file)
@@ -389,7 +389,13 @@ public:
     const size_type osize = o.size();
     const size_type msize = std::min(tsize, osize);
     int r = traits_type::compare(data(), o.data(), msize);
-    if (r == 0) r = tsize - osize;
+    if (r == 0 && tsize != osize) {
+      // We check the signed bit of the subtraction and bit shift it
+      // to produce either 0 or 2. The subtraction yields the
+      // comparison values of either -1 or 1.
+      r = (static_cast<int>(
+             (osize - tsize) >> (CHAR_BIT * sizeof(size_t) - 1)) << 1) - 1;
+    }
     return r;
   }