From 98c4cba4a6bc766a361680664176901bb13d8697 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Fri, 9 Jan 2015 22:28:00 -0800 Subject: [PATCH] folly: Bits: restore type of bitOffset_ to shorter "unsigned int" Summary: My initial change to avoid the -Wsign-compare error neglected the fact that the difference of two unsigned types is also unsigned. That broke some unicorn tests, as seen in D1776343, which worked around the problem by changing the type of bitOffset_ like this: s/unsigned int/size_t. The real problem lay in the distance_to function, which computed the signed difference of two bitOffset_ values. To work properly with the narrower unsigned type, we could either first widen each operand to ssize_t before computing their parenthesized difference, or (as Philip suggested and I prefer), just drop the parentheses and let the signedness of the preceding operands ensure that each successive intermediate result is also signed. Test Plan: Choose one of the failing tests, and ensure it now passes: fbconfig -r unicorn/diskindex4/test:doc_map_test fbmake runtests Also run all unicorn tests, for good measure (still waiting): fbconfig -r unicorn && fbmake runtests Reviewed By: philipp@fb.com, andrei.alexandrescu@fb.com Subscribers: trunkagent, net-systems@, folly-diffs@ FB internal diff: D1776624 Tasks: 5941250 Signature: t1:1776624:1420872874:b1ea8a3f23f21269aa65cbe1647e86a8f622a710 Blame Revision: D1770613 --- folly/Bits.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/folly/Bits.h b/folly/Bits.h index a93be1b6..2136cfad 100644 --- a/folly/Bits.h +++ b/folly/Bits.h @@ -522,10 +522,10 @@ class BitIterator ssize_t distance_to(const BitIterator& other) const { return (other.base_reference() - this->base_reference()) * bitsPerBlock() + - (other.bitOffset_ - bitOffset_); + other.bitOffset_ - bitOffset_; } - size_t bitOffset_; + unsigned int bitOffset_; }; /** -- 2.34.1