Commit 78a84e80 authored by Nathan Bronson's avatar Nathan Bronson Committed by Facebook Github Bot

make a few conversions in folly more explicit

Summary:
These conversions enable a few bits of folly to compile with
more stringent compiler warnings than the baseline.  One site actually
had a bug in an error path, the rest are just churn.

Reviewed By: sathyaphoenix

Differential Revision: D9398429

fbshipit-source-id: d9836eabe93be7aeebd59581df8fb6d278c74112
parent 6dd0f369
...@@ -263,21 +263,21 @@ unsafeTelescope128(char * buffer, size_t room, unsigned __int128 x) { ...@@ -263,21 +263,21 @@ unsafeTelescope128(char * buffer, size_t room, unsigned __int128 x) {
const auto y = x / 10; const auto y = x / 10;
const auto digit = x % 10; const auto digit = x % 10;
buffer[p--] = '0' + digit; buffer[p--] = static_cast<char>('0' + digit);
x = y; x = y;
} }
uint64_t xx = x; // Moving to faster 64-bit division thereafter uint64_t xx = static_cast<uint64_t>(x); // Rest uses faster 64-bit division
while (xx >= 10) { while (xx >= 10) {
const auto y = xx / 10ULL; const auto y = xx / 10ULL;
const auto digit = xx % 10ULL; const auto digit = xx % 10ULL;
buffer[p--] = '0' + digit; buffer[p--] = static_cast<char>('0' + digit);
xx = y; xx = y;
} }
buffer[p] = '0' + xx; buffer[p] = static_cast<char>('0' + xx);
return p; return p;
} }
...@@ -331,7 +331,7 @@ inline uint32_t digits10(uint64_t v) { ...@@ -331,7 +331,7 @@ inline uint32_t digits10(uint64_t v) {
} }
// bits is in the ballpark of log_2(v). // bits is in the ballpark of log_2(v).
const uint8_t leadingZeroes = __builtin_clzll(v); const uint32_t leadingZeroes = __builtin_clzll(v);
const auto bits = 63 - leadingZeroes; const auto bits = 63 - leadingZeroes;
// approximate log_10(v) == log_10(2) * bits. // approximate log_10(v) == log_10(2) * bits.
...@@ -390,12 +390,12 @@ inline uint32_t uint64ToBufferUnsafe(uint64_t v, char *const buffer) { ...@@ -390,12 +390,12 @@ inline uint32_t uint64ToBufferUnsafe(uint64_t v, char *const buffer) {
// Keep these together so a peephole optimization "sees" them and // Keep these together so a peephole optimization "sees" them and
// computes them in one shot. // computes them in one shot.
auto const q = v / 10; auto const q = v / 10;
auto const r = static_cast<char>(v % 10); auto const r = v % 10;
buffer[pos--] = '0' + r; buffer[pos--] = static_cast<char>('0' + r);
v = q; v = q;
} }
// Last digit is trivial to handle // Last digit is trivial to handle
buffer[pos] = static_cast<char>(v) + '0'; buffer[pos] = static_cast<char>(v + '0');
return result; return result;
} }
......
...@@ -1072,7 +1072,7 @@ class FormatValue<std::tuple<Args...>> { ...@@ -1072,7 +1072,7 @@ class FormatValue<std::tuple<Args...>> {
template <size_t K, class Callback> template <size_t K, class Callback>
typename std::enable_if<K == valueCount>::type typename std::enable_if<K == valueCount>::type
doFormatFrom(size_t i, FormatArg& arg, Callback& /* cb */) const { doFormatFrom(size_t i, FormatArg& arg, Callback& /* cb */) const {
arg.enforce("tuple index out of range, max=", i); arg.error("tuple index out of range, max=", i);
} }
template <size_t K, class Callback> template <size_t K, class Callback>
......
...@@ -110,7 +110,8 @@ void cUnescape(StringPiece str, String& out, bool strict) { ...@@ -110,7 +110,8 @@ void cUnescape(StringPiece str, String& out, bool strict) {
unsigned char val = 0; unsigned char val = 0;
for (int i = 0; i < 3 && p != str.end() && *p >= '0' && *p <= '7'; for (int i = 0; i < 3 && p != str.end() && *p >= '0' && *p <= '7';
++i, ++p) { ++i, ++p) {
val = (val << 3) | (*p - '0'); val <<= 3;
val |= (*p - '0');
} }
out.push_back(val); out.push_back(val);
last = p; last = p;
...@@ -129,7 +130,8 @@ void cUnescape(StringPiece str, String& out, bool strict) { ...@@ -129,7 +130,8 @@ void cUnescape(StringPiece str, String& out, bool strict) {
for (; (p != str.end() && for (; (p != str.end() &&
(h = detail::hexTable[static_cast<unsigned char>(*p)]) < 16); (h = detail::hexTable[static_cast<unsigned char>(*p)]) < 16);
++p) { ++p) {
val = (val << 4) | h; val <<= 4;
val |= h;
} }
out.push_back(val); out.push_back(val);
last = p; last = p;
......
...@@ -577,7 +577,7 @@ struct alignas(kRequiredVectorAlignment) F14Chunk { ...@@ -577,7 +577,7 @@ struct alignas(kRequiredVectorAlignment) F14Chunk {
void copyOverflowInfoFrom(F14Chunk const& rhs) { void copyOverflowInfoFrom(F14Chunk const& rhs) {
FOLLY_SAFE_DCHECK(hostedOverflowCount() == 0, ""); FOLLY_SAFE_DCHECK(hostedOverflowCount() == 0, "");
control_ += rhs.control_ & 0xf0; control_ += static_cast<uint8_t>(rhs.control_ & 0xf0);
outboundOverflowCount_ = rhs.outboundOverflowCount_; outboundOverflowCount_ = rhs.outboundOverflowCount_;
} }
...@@ -625,13 +625,14 @@ struct alignas(kRequiredVectorAlignment) F14Chunk { ...@@ -625,13 +625,14 @@ struct alignas(kRequiredVectorAlignment) F14Chunk {
} }
} }
uint8_t tag(std::size_t index) const { std::size_t tag(std::size_t index) const {
return tags_[index]; return tags_[index];
} }
void setTag(std::size_t index, uint8_t tag) { void setTag(std::size_t index, std::size_t tag) {
FOLLY_SAFE_DCHECK(this != emptyInstance() && (tag & 0x80) != 0, ""); FOLLY_SAFE_DCHECK(
tags_[index] = tag; this != emptyInstance() && tag >= 0x80 && tag <= 0xff, "");
tags_[index] = static_cast<uint8_t>(tag);
} }
void clearTag(std::size_t index) { void clearTag(std::size_t index) {
......
...@@ -47,8 +47,8 @@ std::ostream& operator<<(std::ostream& xo, Histo const& histo) { ...@@ -47,8 +47,8 @@ std::ostream& operator<<(std::ostream& xo, Histo const& histo) {
} }
partial += histo.data[i]; partial += histo.data[i];
if (histo.data[i] > 0) { if (histo.data[i] > 0) {
xo << i << ": " << histo.data[i] << " (" << (partial * 100.0 / sum) xo << i << ": " << histo.data[i] << " ("
<< "%)"; << (static_cast<double>(partial) * 100.0 / sum) << "%)";
} }
} }
xo << "]"; xo << "]";
...@@ -73,7 +73,7 @@ double expectedProbe(std::vector<std::size_t> const& probeLengths) { ...@@ -73,7 +73,7 @@ double expectedProbe(std::vector<std::size_t> const& probeLengths) {
sum += i * probeLengths[i]; sum += i * probeLengths[i];
count += probeLengths[i]; count += probeLengths[i];
} }
return static_cast<double>(sum) / count; return static_cast<double>(sum) / static_cast<double>(count);
} }
// Returns i such that probeLengths elements 0 to i (inclusive) account // Returns i such that probeLengths elements 0 to i (inclusive) account
...@@ -457,7 +457,9 @@ std::ostream& operator<<(std::ostream& xo, F14TableStats const& stats) { ...@@ -457,7 +457,9 @@ std::ostream& operator<<(std::ostream& xo, F14TableStats const& stats) {
xo << " valueBytes: " << (stats.size * stats.valueSize) << std::endl; xo << " valueBytes: " << (stats.size * stats.valueSize) << std::endl;
xo << " overheadBytes: " << stats.overheadBytes << std::endl; xo << " overheadBytes: " << stats.overheadBytes << std::endl;
if (stats.size > 0) { if (stats.size > 0) {
xo << " overheadBytesPerKey: " << (stats.overheadBytes * 1.0 / stats.size) xo << " overheadBytesPerKey: "
<< (static_cast<double>(stats.overheadBytes) /
static_cast<double>(stats.size))
<< std::endl; << std::endl;
} }
xo << "}"; xo << "}";
......
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