folly/Range.cpp: avoid -Werror=sign-compare error with gcc-4.9
authorJim Meyering <meyering@fb.com>
Tue, 6 Jan 2015 00:53:50 +0000 (16:53 -0800)
committerViswanath Sivakumar <viswanath@fb.com>
Tue, 13 Jan 2015 19:01:03 +0000 (11:01 -0800)
Summary:
* folly/Range.cpp (scanHaystackBlock): This method mistakenly
declared its "idx" (aka blockStartIdx) parameter to have signed type.
It is logically an unsigned type and is compared only with other
variables of unsigned type, so make it unsigned.
Here's the diagnostic:
folly/Range.cpp:202:44: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
folly/Range.cpp: In instantiation of 'size_t folly::detail::scanHaystackBlock(folly::StringPiece, folly::StringPiece, int64_t) [with bool HAYSTACK_ALIGNED = true; size_t = long unsigned int; folly::StringPiece = folly::Range<const char*>; int64_t = long int]':

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

Reviewed By: robbert@fb.com, philipp@fb.com

Subscribers: folly-diffs@

FB internal diff: D1765590

Signature: t1:1765590:1420506036:7cbe2c454ad1f018a1c0aa5112a38bed1b2ac673

folly/Range.cpp

index 42ee048d638dc25738794c70b28b95c86325868e..343ba7284c21bad813148861a11b1903e1002f72 100644 (file)
@@ -179,7 +179,7 @@ size_t qfind_first_byte_of_byteset(const StringPiece haystack,
 template <bool HAYSTACK_ALIGNED>
 size_t scanHaystackBlock(const StringPiece haystack,
                          const StringPiece needles,
 template <bool HAYSTACK_ALIGNED>
 size_t scanHaystackBlock(const StringPiece haystack,
                          const StringPiece needles,
-                         int64_t idx)
+                         uint64_t idx)
 // inline is okay because it's only called from other sse4.2 functions
   __attribute__ ((__target__("sse4.2")))
 // Turn off ASAN because the "arr2 = ..." assignment in the loop below reads
 // inline is okay because it's only called from other sse4.2 functions
   __attribute__ ((__target__("sse4.2")))
 // Turn off ASAN because the "arr2 = ..." assignment in the loop below reads
@@ -195,7 +195,7 @@ size_t scanHaystackBlock(const StringPiece haystack,
 template <bool HAYSTACK_ALIGNED>
 size_t scanHaystackBlock(const StringPiece haystack,
                          const StringPiece needles,
 template <bool HAYSTACK_ALIGNED>
 size_t scanHaystackBlock(const StringPiece haystack,
                          const StringPiece needles,
-                         int64_t blockStartIdx) {
+                         uint64_t blockStartIdx) {
   DCHECK_GT(needles.size(), 16);  // should handled by *needles16() method
   DCHECK(blockStartIdx + 16 <= haystack.size() ||
          (PAGE_FOR(haystack.data() + blockStartIdx) ==
   DCHECK_GT(needles.size(), 16);  // should handled by *needles16() method
   DCHECK(blockStartIdx + 16 <= haystack.size() ||
          (PAGE_FOR(haystack.data() + blockStartIdx) ==