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