Commit 2ab6db1e authored by Jim Meyering's avatar Jim Meyering Committed by Viswanath Sivakumar

folly/stats/Histogram-defs.h: avoid -Wsign-compare error

Summary:
* folly/stats/Histogram-defs.h (HistogramBuckets): Take the unusual
approach of converting "numBuckets" to signed, because we cannot
cast "max-min" (a known positive value) to an unsigned type --
we don't have an unsigned variant of ValueType.
This avoids the following error from gcc-4.9:

folly/stats/Histogram-defs.h:41:31: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: ldbrandy@fb.com

Subscribers: trunkagent, net-systems@, folly-diffs@

FB internal diff: D1770129

Tasks: 5941250

Signature: t1:1770129:1420745311:c447e59f1730abafdf0b962e70f0886ae1d48db1
parent 9d9b01ef
...@@ -36,7 +36,9 @@ HistogramBuckets<T, BucketT>::HistogramBuckets(ValueType bucketSize, ...@@ -36,7 +36,9 @@ HistogramBuckets<T, BucketT>::HistogramBuckets(ValueType bucketSize,
CHECK_GT(bucketSize_, ValueType(0)); CHECK_GT(bucketSize_, ValueType(0));
CHECK_LT(min_, max_); CHECK_LT(min_, max_);
unsigned int numBuckets = (max - min) / bucketSize; // Deliberately make this a signed type, because we're about
// to compare it against max-min, which is nominally signed, too.
int numBuckets = (max - min) / bucketSize;
// Round up if the bucket size does not fit evenly // Round up if the bucket size does not fit evenly
if (numBuckets * bucketSize < max - min) { if (numBuckets * bucketSize < max - min) {
++numBuckets; ++numBuckets;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment