From: Kyle Dent <kmdent@fb.com>
Date: Wed, 28 Jan 2015 19:33:49 +0000 (-0800)
Subject: Fixing a -Wshorten-64-32 issues in folly for liger.
X-Git-Tag: v0.23.0~14
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=80702b5d1ad84dd21cfa7c023810ec2c36991307;p=folly.git

Fixing a -Wshorten-64-32 issues in folly for liger.

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

diff --git a/folly/Range.h b/folly/Range.h
index f22d30e9..2ce83f8d 100644
--- a/folly/Range.h
+++ b/folly/Range.h
@@ -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;
   }