Commit 3e0ea102 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot

Make a few implicit truncations either explicit, or not truncate

Summary: This silences a few warnings under MSVC, and gets Folly closer to being able to compile with `-Wconversion` enabled.

Reviewed By: yfeldblum

Differential Revision: D5100686

fbshipit-source-id: e5e04c7aa143597e151a56a4d1f90dda26d0033b
parent 523ca7d7
......@@ -188,8 +188,8 @@ IPAddressV6 IPAddressV6::fromInverseArpaName(const std::string& arpaname) {
std::array<char, IPAddressV6::kToFullyQualifiedSize> ip;
size_t pos = 0;
int count = 0;
for (int p = pieces.size() - 1; p >= 0; p--) {
ip[pos] = pieces[p][0];
for (size_t i = 1; i <= pieces.size(); i++) {
ip[pos] = pieces[pieces.size() - i][0];
pos++;
count++;
// add ':' every 4 chars
......
......@@ -145,7 +145,7 @@ struct EliasFanoEncoderV2 {
forwardPointers_(reinterpret_cast<SkipValueType*>(
result.forwardPointers)),
result_(result) {
std::fill(result.data.begin(), result.data.end(), 0);
std::fill(result.data.begin(), result.data.end(), '\0');
}
EliasFanoEncoderV2(size_t size, ValueType upperBound)
......
......@@ -108,7 +108,7 @@ void JemallocNodumpAllocator::deallocate(void* p) {
void JemallocNodumpAllocator::deallocate(void* p, void* userData) {
const uint64_t flags = reinterpret_cast<uint64_t>(userData);
dallocx != nullptr ? dallocx(p, flags) : free(p);
dallocx != nullptr ? dallocx(p, static_cast<int>(flags)) : free(p);
}
JemallocNodumpAllocator& globalJemallocNodumpAllocator() {
......
......@@ -702,10 +702,10 @@ void AsyncSSLSocket::connect(
assert(sslState_ == STATE_UNINIT);
noTransparentTls_ = true;
totalConnectTimeout_ = totalConnectTimeout;
AsyncSSLSocketConnector* connector =
new AsyncSSLSocketConnector(this, callback, totalConnectTimeout.count());
AsyncSSLSocketConnector* connector = new AsyncSSLSocketConnector(
this, callback, int(totalConnectTimeout.count()));
AsyncSocket::connect(
connector, address, connectTimeout.count(), options, bindAddr);
connector, address, int(connectTimeout.count()), options, bindAddr);
}
bool AsyncSSLSocket::needsPeerVerification() const {
......@@ -1701,9 +1701,9 @@ int AsyncSSLSocket::bioRead(BIO* b, char* out, int outl) {
queue.append(std::move(sslSock->preReceivedData_));
queue.trimStart(len);
sslSock->preReceivedData_ = queue.move();
return len;
return static_cast<int>(len);
} else {
auto result = recv(OpenSSLUtils::getBioFd(b, nullptr), out, outl, 0);
auto result = int(recv(OpenSSLUtils::getBioFd(b, nullptr), out, outl, 0));
if (result <= 0 && OpenSSLUtils::getBioShouldRetryWrite(result)) {
BIO_set_retry_read(b);
}
......
......@@ -120,7 +120,7 @@ bool OpenSSLUtils::validatePeerCertNames(X509* cert,
}
}
for (size_t i = 0; i < (size_t)sk_GENERAL_NAME_num(altNames); i++) {
for (int i = 0; i < sk_GENERAL_NAME_num(altNames); i++) {
auto name = sk_GENERAL_NAME_value(altNames, i);
if ((addr4 != nullptr || addr6 != nullptr) && name->type == GEN_IPADD) {
// Extra const-ness for paranoia
......
......@@ -538,7 +538,7 @@ TEST(IOBuf, QueueAppenderPushAtMostFillBuffer) {
QueueAppender appender{&queue, 125};
std::vector<uint8_t> data;
data.resize(1000);
std::iota(data.begin(), data.end(), 0);
std::iota(data.begin(), data.end(), uint8_t(0));
// Add 100 byte
appender.pushAtMost(data.data(), 100);
// Add 900 bytes
......
......@@ -177,7 +177,7 @@ TEST(IOBufQueue, SplitZero) {
TEST(IOBufQueue, Preallocate) {
IOBufQueue queue(clOptions);
queue.append(string("Hello"));
pair<void*,uint32_t> writable = queue.preallocate(2, 64, 64);
pair<void*, uint64_t> writable = queue.preallocate(2, 64, 64);
checkConsistency(queue);
EXPECT_NE((void*)nullptr, writable.first);
EXPECT_LE(2, writable.second);
......
......@@ -135,6 +135,6 @@ TEST(Random, sanity) {
}
EXPECT_EQ(
vals.size(),
std::unordered_set<uint32_t>(vals.begin(), vals.end()).size());
std::unordered_set<uint64_t>(vals.begin(), vals.end()).size());
}
}
......@@ -58,16 +58,14 @@ void ArenaTester::allocate(size_t count, size_t maxSize) {
for (size_t i = 0; i < count; i++) {
size_t size = sizeDist(rnd);
uint8_t* p = static_cast<uint8_t*>(arena_->allocate(size));
areas_.emplace_back(rnd() & 0xff, Range<uint8_t*>(p, size));
areas_.emplace_back(uint8_t(rnd() & 0xff), Range<uint8_t*>(p, size));
}
// Fill each area with a different value, to prove that they don't overlap
// Fill in random order.
std::random_shuffle(
areas_.begin(), areas_.end(),
[&rnd] (int n) -> int {
return std::uniform_int_distribution<uint32_t>(0, n-1)(rnd);
});
std::random_shuffle(areas_.begin(), areas_.end(), [&rnd](ptrdiff_t n) {
return std::uniform_int_distribution<uint32_t>(0, n - 1)(rnd);
});
for (auto& p : areas_) {
std::fill(p.second.begin(), p.second.end(), p.first);
......
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