From a14ee3e66c911037a0d0a8a36339627718185382 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 24 Dec 2019 16:46:10 +0300 Subject: [PATCH] Do not use functional cast on integers. GitOrigin-RevId: 1ebcf0e9a9b004039d32b6363140387bca7d7722 --- td/mtproto/Transport.cpp | 2 +- tdnet/td/net/Socks5.cpp | 5 +++-- tdutils/test/ConcurrentHashMap.cpp | 9 +++++---- test/fuzz_url.cpp | 2 +- test/http.cpp | 2 +- test/set_with_position.cpp | 2 +- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/td/mtproto/Transport.cpp b/td/mtproto/Transport.cpp index 3f03a769..f6f1d56a 100644 --- a/td/mtproto/Transport.cpp +++ b/td/mtproto/Transport.cpp @@ -337,7 +337,7 @@ size_t Transport::write_no_crypto(const Storer &storer, PacketInfo *info, Mutabl return size; } // NoCryptoHeader - as(dest.begin()) = uint64(0); + as(dest.begin()) = 0; auto real_size = storer.store(dest.ubegin() + sizeof(uint64)); CHECK(real_size == storer.size()); return size; diff --git a/tdnet/td/net/Socks5.cpp b/tdnet/td/net/Socks5.cpp index 0115dcaf..d2898ca7 100644 --- a/tdnet/td/net/Socks5.cpp +++ b/tdnet/td/net/Socks5.cpp @@ -40,7 +40,7 @@ Status Socks5::wait_greeting_response() { auto buffer_slice = buf.read_as_buffer_slice(2); auto slice = buffer_slice.as_slice(); if (slice[0] != '\x05') { - return Status::Error(PSLICE() << "Unsupported socks protocol version " << int(slice[0])); + return Status::Error(PSLICE() << "Unsupported socks protocol version " << static_cast(slice[0])); } auto authentication_method = slice[1]; if (authentication_method == '\0') { @@ -83,7 +83,8 @@ Status Socks5::wait_password_response() { auto buffer_slice = buf.read_as_buffer_slice(2); auto slice = buffer_slice.as_slice(); if (slice[0] != '\x01') { - return Status::Error(PSLICE() << "Unsupported socks subnegotiation protocol version " << int(slice[0])); + return Status::Error(PSLICE() << "Unsupported socks subnegotiation protocol version " + << static_cast(slice[0])); } if (slice[1] != '\x00') { return Status::Error("Wrong username or password"); diff --git a/tdutils/test/ConcurrentHashMap.cpp b/tdutils/test/ConcurrentHashMap.cpp index 8a2d22aa..b6f90367 100644 --- a/tdutils/test/ConcurrentHashMap.cpp +++ b/tdutils/test/ConcurrentHashMap.cpp @@ -6,6 +6,7 @@ // #include "td/utils/benchmark.h" #include "td/utils/ConcurrentHashTable.h" +#include "td/utils/misc.h" #include "td/utils/port/thread.h" #include "td/utils/SpinLock.h" #include "td/utils/tests.h" @@ -210,8 +211,8 @@ class HashMapBenchmark : public td::Benchmark { size_t r = n * (i + 1) / threads_n; threads.emplace_back([l, r, this] { for (size_t i = l; i < r; i++) { - auto x = int((i + 1) * mul_ % n_) + 3; - auto y = int(i + 2); + auto x = td::narrow_cast((i + 1) * mul_ % n_) + 3; + auto y = td::narrow_cast(i + 2); hash_map->insert(x, y); } }); @@ -223,8 +224,8 @@ class HashMapBenchmark : public td::Benchmark { void tear_down() override { for (int i = 0; i < n_; i++) { - auto x = int((i + 1) * mul_ % n_) + 3; - auto y = int(i + 2); + auto x = td::narrow_cast((i + 1) * mul_ % n_) + 3; + auto y = td::narrow_cast(i + 2); ASSERT_EQ(y, hash_map->find(x, -1)); } queries.clear(); diff --git a/test/fuzz_url.cpp b/test/fuzz_url.cpp index 0a3113a7..ffe0915f 100644 --- a/test/fuzz_url.cpp +++ b/test/fuzz_url.cpp @@ -17,7 +17,7 @@ static td::string get_utf_string(td::Slice from) { td::string res; td::string alph = " ab@./01#"; for (auto c : from) { - res += alph[td::uint8(c) % alph.size()]; + res += alph[static_cast(c) % alph.size()]; } LOG(ERROR) << res; return res; diff --git a/test/http.cpp b/test/http.cpp index 8268ee64..e7b80cc6 100644 --- a/test/http.cpp +++ b/test/http.cpp @@ -47,7 +47,7 @@ static string make_chunked(string str) { auto v = rand_split(str); string res; for (auto &s : v) { - res += PSTRING() << format::as_hex_dump(int(s.size())); + res += PSTRING() << format::as_hex_dump(static_cast(s.size())); res += "\r\n"; res += s; res += "\r\n"; diff --git a/test/set_with_position.cpp b/test/set_with_position.cpp index d9f2f9e0..9419cdd7 100644 --- a/test/set_with_position.cpp +++ b/test/set_with_position.cpp @@ -233,7 +233,7 @@ static void test_speed() { std::vector> sets(total_size); for (size_t i = 0; i < sets.size(); i++) { sets[i] = make_unique(); - sets[i]->add(int(i)); + sets[i]->add(narrow_cast(i)); } for (size_t d = 1; d < sets.size(); d *= 2) { for (size_t i = 0; i < sets.size(); i += 2 * d) {