From 7cae56406bd38fce78099c3c0ec21138aef276e2 Mon Sep 17 00:00:00 2001 From: Steve O'Brien Date: Sun, 7 Jun 2015 19:06:26 -0700 Subject: [PATCH] Conv.h: fix a type error caught by clang Summary: Need to be more explicit about types; it was trying to add types deduced to be `unsigned long` + `long` which didn't agree and could be an overflow. Be explicit anyway about the types involved. Appease Clang, and also make the code more obvious to the reader. Test Plan: Tried with gcc 4.9, clang 3.5, clang 3.6. Reviewed By: yfeldblum@fb.com Subscribers: mathieubaudet, maoy, folly-diffs@, yzhan, yfeldblum, chalfant FB internal diff: D2134814 Tasks: 7337462 Signature: t1:2134814:1433726862:5dd80b198187c610f793e26160919922863a22a2 Blame Revision: D1934777 --- folly/Conv.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/folly/Conv.h b/folly/Conv.h index cf7d8662..ccb394b9 100644 --- a/folly/Conv.h +++ b/folly/Conv.h @@ -256,12 +256,11 @@ inline uint32_t digits10(uint64_t v) { // approximate log_10(v) == log_10(2) * bits. // Integer magic below: 77/256 is appx. 0.3010 (log_10(2)). // The +1 is to make this the ceiling of the log_10 estimate. - const auto minLength = 1 + ((bits * 77) >> 8); + const uint32_t minLength = 1 + ((bits * 77) >> 8); // return that log_10 lower bound, plus adjust if input >= 10^(that bound) // in case there's a small error and we misjudged length. - return minLength + - (UNLIKELY (v >= powersOf10[minLength])); + return minLength + (uint32_t) (UNLIKELY (v >= powersOf10[minLength])); #else -- 2.34.1