Skip to content

Commit

Permalink
Use auto types in folly to address -Wshorten-64-to-32
Browse files Browse the repository at this point in the history
Summary: To make things easier to review, I've moved the auto types over here.

Reviewed By: Gownta

Differential Revision: D57686669

fbshipit-source-id: cbc89c9a9cce5850e0f5f30a769ae410e563821d
  • Loading branch information
r-barnes authored and facebook-github-bot committed Sep 23, 2024
1 parent 48b5ca0 commit ffe719d
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 37 deletions.
2 changes: 1 addition & 1 deletion third-party/folly/src/folly/Benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ void printDefaultHeaderContents(std::string_view file, size_t columns) {
} else {
std::string truncatedFile = std::string(file.begin(), file.end());
constexpr std::string_view overflowFilePrefix = "[...]";
const int overflow = truncatedFile.size() - maxFileNameChars;
const auto overflow = truncatedFile.size() - maxFileNameChars;
truncatedFile.erase(0, overflow);
truncatedFile.replace(0, overflowFilePrefix.size(), overflowFilePrefix);
printHeaderContents(truncatedFile);
Expand Down
2 changes: 1 addition & 1 deletion third-party/folly/src/folly/Subprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ void Subprocess::closeInheritedFds(const Options::FdMap& fdActions) {
#endif
// If not running on Linux or if we failed to open /proc/self/fd, try to close
// all possible open file descriptors.
for (int fd = sysconf(_SC_OPEN_MAX) - 1; fd >= 3; --fd) {
for (auto fd = sysconf(_SC_OPEN_MAX) - 1; fd >= 3; --fd) {
if (fdActions.count(fd) == 0) {
::close(fd);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void SymbolizePrinter::print(const SymbolizedFrame& frame) {
doPrint(fileBuf);

char buf[to_ascii_size_max_decimal<decltype(frame.location.line)>];
uint32_t n = to_ascii_decimal(buf, frame.location.line);
const auto n = to_ascii_decimal(buf, frame.location.line);
doPrint(":");
doPrint(StringPiece(buf, n));
} else {
Expand Down
4 changes: 2 additions & 2 deletions third-party/folly/src/folly/detail/Futex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace {
#endif

int nativeFutexWake(const void* addr, int count, uint32_t wakeMask) {
int rv = syscall(
const auto rv = syscall(
__NR_futex,
addr, /* addr1 */
FUTEX_WAKE_BITSET | FUTEX_PRIVATE_FLAG, /* op */
Expand Down Expand Up @@ -123,7 +123,7 @@ FutexResult nativeFutexWaitImpl(

// Unlike FUTEX_WAIT, FUTEX_WAIT_BITSET requires an absolute timeout
// value - http://locklessinc.com/articles/futex_cheat_sheet/
int rv = syscall(
const auto rv = syscall(
__NR_futex,
addr, /* addr1 */
op, /* op */
Expand Down
10 changes: 5 additions & 5 deletions third-party/folly/src/folly/io/async/SSLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void configureProtocolVersion(SSL_CTX* ctx, SSLContext::SSLVersion version) {
// do nothing
break;
}
int setMinProtoResult = SSL_CTX_set_min_proto_version(ctx, minVersion);
const auto setMinProtoResult = SSL_CTX_set_min_proto_version(ctx, minVersion);
DCHECK(setMinProtoResult == 1)
<< sformat("unsupported min TLS protocol version: 0x{:04x}", minVersion);
}
Expand Down Expand Up @@ -141,7 +141,7 @@ void SSLContext::setClientECCurvesList(
}
std::string ecCurvesList;
join(":", ecCurves, ecCurvesList);
int rc = SSL_CTX_set1_curves_list(ctx_, ecCurvesList.c_str());
const auto rc = SSL_CTX_set1_curves_list(ctx_, ecCurvesList.c_str());
if (rc == 0) {
throw std::runtime_error("SSL_CTX_set1_curves_list " + getErrors());
}
Expand All @@ -153,7 +153,7 @@ void SSLContext::setSupportedGroups(const std::vector<std::string>& groups) {
}
std::string groupsList;
join(":", groups, groupsList);
int rc = SSL_CTX_set1_groups_list(ctx_, groupsList.c_str());
const auto rc = SSL_CTX_set1_groups_list(ctx_, groupsList.c_str());
if (rc == 0) {
throw std::runtime_error("SSL_CTX_set1_curves " + getErrors());
}
Expand Down Expand Up @@ -201,15 +201,15 @@ void SSLContext::setX509VerifyParam(
}

void SSLContext::setCiphersOrThrow(const std::string& ciphers) {
int rc = SSL_CTX_set_cipher_list(ctx_, ciphers.c_str());
const auto rc = SSL_CTX_set_cipher_list(ctx_, ciphers.c_str());
if (rc == 0) {
throw std::runtime_error("SSL_CTX_set_cipher_list: " + getErrors());
}
providedCiphersString_ = ciphers;
}

void SSLContext::setSigAlgsOrThrow(const std::string& sigalgs) {
int rc = SSL_CTX_set1_sigalgs_list(ctx_, sigalgs.c_str());
const auto rc = SSL_CTX_set1_sigalgs_list(ctx_, sigalgs.c_str());
if (rc == 0) {
throw std::runtime_error("SSL_CTX_set1_sigalgs_list " + getErrors());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class UDPAcceptor : public AsyncUDPServerSocket::Callback {
if (params.gro == -1) {
socket->write(client, data->clone());
} else {
int total = data->length();
int64_t total = data->length();
size_t offset = 0;
while (total > 0) {
auto size = (total > params.gro) ? params.gro : total;
Expand Down
4 changes: 2 additions & 2 deletions third-party/folly/src/folly/io/async/test/EventBaseTestLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ FOLLY_ALWAYS_INLINE ssize_t writeToFD(int fd, size_t length) {
auto bufv = std::vector<char>(length);
auto buf = bufv.data();
memset(buf, 'a', length);
ssize_t rc = write(fd, buf, length);
const auto rc = write(fd, buf, length);
CHECK_EQ(rc, length);
return rc;
}
Expand Down Expand Up @@ -113,7 +113,7 @@ FOLLY_ALWAYS_INLINE size_t readUntilEmpty(int fd) {
char buf[BUF_SIZE];
size_t bytesRead = 0;
while (true) {
int rc = read(fd, buf, sizeof(buf));
const auto rc = read(fd, buf, sizeof(buf));
if (rc == 0) {
CHECK(false) << "unexpected EOF";
} else if (rc < 0) {
Expand Down
18 changes: 9 additions & 9 deletions third-party/folly/src/folly/io/async/test/EventHandlerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class EventHandlerOobTest : public ::testing::Test {
TEST_F(EventHandlerOobTest, EPOLLPRI) {
auto clientOps = [](int fd) {
char buffer[] = "banana";
int n = send(fd, buffer, strlen(buffer) + 1, MSG_OOB);
const auto n = send(fd, buffer, strlen(buffer) + 1, MSG_OOB);
LOG(INFO) << "Client send finished";
PCHECK(n > 0);
};
Expand All @@ -293,7 +293,7 @@ TEST_F(EventHandlerOobTest, EPOLLPRI) {
void handlerReady(uint16_t events) noexcept override {
EXPECT_TRUE(EventHandler::EventFlags::PRI & events);
std::array<char, 255> buffer;
int n = read(fd_, buffer.data(), buffer.size());
auto n = read(fd_, buffer.data(), buffer.size());
//
// NB: we sent 7 bytes, but only received 6. The last byte
// has been stored in the OOB buffer.
Expand Down Expand Up @@ -322,13 +322,13 @@ TEST_F(EventHandlerOobTest, OOB_AND_NORMAL_DATA) {
{
// OOB buffer can only hold one byte in most implementations
std::array<char, 2> buffer = {"X"};
int n = send(sockfd, buffer.data(), 1, MSG_OOB);
const auto n = send(sockfd, buffer.data(), 1, MSG_OOB);
PCHECK(n > 0);
}

{
std::array<char, 7> buffer = {"banana"};
int n = send(sockfd, buffer.data(), buffer.size(), 0);
const auto n = send(sockfd, buffer.data(), buffer.size(), 0);
PCHECK(n > 0);
}
};
Expand All @@ -343,15 +343,15 @@ TEST_F(EventHandlerOobTest, OOB_AND_NORMAL_DATA) {
void handlerReady(uint16_t events) noexcept override {
std::array<char, 255> buffer;
if (events & EventHandler::EventFlags::PRI) {
int n = recv(fd_, buffer.data(), buffer.size(), MSG_OOB);
const auto n = recv(fd_, buffer.data(), buffer.size(), MSG_OOB);
EXPECT_EQ(1, n);
EXPECT_EQ("X", std::string(buffer.data(), 1));
registerHandler(EventHandler::EventFlags::READ);
return;
}

if (events & EventHandler::EventFlags::READ) {
int n = recv(fd_, buffer.data(), buffer.size(), 0);
const auto n = recv(fd_, buffer.data(), buffer.size(), 0);
EXPECT_EQ(7, n);
EXPECT_EQ("banana", std::string(buffer.data()));
eb_->terminateLoopSoon();
Expand All @@ -376,13 +376,13 @@ TEST_F(EventHandlerOobTest, SWALLOW_OOB) {
auto clientOps = [](int sockfd) {
{
std::array<char, 2> buffer = {"X"};
int n = send(sockfd, buffer.data(), 1, MSG_OOB);
const auto n = send(sockfd, buffer.data(), 1, MSG_OOB);
PCHECK(n > 0);
}

{
std::array<char, 7> buffer = {"banana"};
int n = send(sockfd, buffer.data(), buffer.size(), 0);
const auto n = send(sockfd, buffer.data(), buffer.size(), 0);
PCHECK(n > 0);
}
};
Expand All @@ -397,7 +397,7 @@ TEST_F(EventHandlerOobTest, SWALLOW_OOB) {
void handlerReady(uint16_t events) noexcept override {
std::array<char, 255> buffer;
ASSERT_TRUE(events & EventHandler::EventFlags::READ);
int n = recv(fd_, buffer.data(), buffer.size(), 0);
const auto n = recv(fd_, buffer.data(), buffer.size(), 0);
EXPECT_EQ(7, n);
EXPECT_EQ("banana", std::string(buffer.data()));
}
Expand Down
3 changes: 2 additions & 1 deletion third-party/folly/src/folly/io/async/test/SSLContextTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ TEST_F(SSLContextTest, TestSetInvalidCiphersuite) {

TEST_F(SSLContextTest, TestTLS13MinVersion) {
SSLContext sslContext{SSLContext::SSLVersion::TLSv1_3};
int minProtoVersion = SSL_CTX_get_min_proto_version(sslContext.getSSLCtx());
const auto minProtoVersion =
SSL_CTX_get_min_proto_version(sslContext.getSSLCtx());
EXPECT_EQ(minProtoVersion, TLS1_3_VERSION);
}

Expand Down
12 changes: 6 additions & 6 deletions third-party/folly/src/folly/io/async/test/TimeUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ namespace folly {

#ifdef __linux__
static int getLinuxVersion(StringPiece release) {
auto dot1 = release.find('.');
const auto dot1 = release.find('.');
if (dot1 == StringPiece::npos) {
throw std::invalid_argument("could not find first dot");
}
auto v1 = folly::to<int>(release.subpiece(0, dot1));
const auto v1 = folly::to<int>(release.subpiece(0, dot1));

auto dot2 = release.find('.', dot1 + 1);
const auto dot2 = release.find('.', dot1 + 1);
if (dot2 == StringPiece::npos) {
throw std::invalid_argument("could not find second dot");
}
auto v2 = folly::to<int>(release.subpiece(dot1 + 1, dot2 - (dot1 + 1)));
const auto v2 = folly::to<int>(release.subpiece(dot1 + 1, dot2 - (dot1 + 1)));

int dash = release.find('-', dot2 + 1);
auto v3 = folly::to<int>(release.subpiece(dot2 + 1, dash - (dot2 + 1)));
const auto dash = release.find('-', dot2 + 1);
const auto v3 = folly::to<int>(release.subpiece(dot2 + 1, dash - (dot2 + 1)));

return ((v1 * 1000 + v2) * 1000) + v3;
}
Expand Down
2 changes: 1 addition & 1 deletion third-party/folly/src/folly/io/test/IOBufTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void prepend(std::unique_ptr<IOBuf>& buf, StringPiece str) {

TEST(IOBuf, Simple) {
unique_ptr<IOBuf> buf(IOBuf::create(100));
uint32_t cap = buf->capacity();
const auto cap = buf->capacity();
EXPECT_LE(100, cap);
EXPECT_EQ(0, buf->headroom());
EXPECT_EQ(0, buf->length());
Expand Down
4 changes: 2 additions & 2 deletions third-party/folly/src/folly/test/ConvBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ unsigned u64ToAsciiTable(uint64_t value, char* dst) {
"80818283848586878889"
"90919293949596979899";

uint32_t const length = to_ascii_size_decimal(value);
uint32_t next = length - 1;
auto const length = to_ascii_size_decimal(value);
auto next = length - 1;
while (value >= 100) {
auto const i = (value % 100) * 2;
value /= 100;
Expand Down
10 changes: 5 additions & 5 deletions third-party/folly/src/folly/test/stl_tests/StlVectorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2325,10 +2325,10 @@ STL_TEST(
a,
p) {
DataState<Vector> dsa(a);
int idx = distance(a.begin(), p);
auto am = a.get_allocator();
const auto idx = distance(a.begin(), p);
const auto am = a.get_allocator();

auto q = a.emplace(p, 44);
const auto q = a.emplace(p, 44);

ASSERT_TRUE(am == a.get_allocator());
ASSERT_EQ(idx, distance(a.begin(), q)) << "incorrect iterator returned";
Expand All @@ -2349,12 +2349,12 @@ STL_TEST(
SKIP();
}
DataState<Vector> dsa(a);
int idx = distance(a.begin(), p);
const auto idx = distance(a.begin(), p);
int tval = convertToInt(t);
auto am = a.get_allocator();
const auto& ct = t;

auto q = a.insert(p, ct);
const auto q = a.insert(p, ct);

ASSERT_TRUE(am == a.get_allocator());
ASSERT_EQ(idx, distance(a.begin(), q)) << "incorrect iterator returned";
Expand Down

0 comments on commit ffe719d

Please sign in to comment.