Do not use functional cast on integers.

GitOrigin-RevId: 1ebcf0e9a9b004039d32b6363140387bca7d7722
This commit is contained in:
levlam 2019-12-24 16:46:10 +03:00
parent 9dde153313
commit a14ee3e66c
6 changed files with 12 additions and 10 deletions

View File

@ -337,7 +337,7 @@ size_t Transport::write_no_crypto(const Storer &storer, PacketInfo *info, Mutabl
return size;
}
// NoCryptoHeader
as<uint64>(dest.begin()) = uint64(0);
as<uint64>(dest.begin()) = 0;
auto real_size = storer.store(dest.ubegin() + sizeof(uint64));
CHECK(real_size == storer.size());
return size;

View File

@ -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<int>(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<int>(slice[0]));
}
if (slice[1] != '\x00') {
return Status::Error("Wrong username or password");

View File

@ -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<int>((i + 1) * mul_ % n_) + 3;
auto y = td::narrow_cast<int>(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<int>((i + 1) * mul_ % n_) + 3;
auto y = td::narrow_cast<int>(i + 2);
ASSERT_EQ(y, hash_map->find(x, -1));
}
queries.clear();

View File

@ -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<td::uint8>(c) % alph.size()];
}
LOG(ERROR) << res;
return res;

View File

@ -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<int32>(s.size()));
res += "\r\n";
res += s;
res += "\r\n";

View File

@ -233,7 +233,7 @@ static void test_speed() {
std::vector<unique_ptr<Set>> sets(total_size);
for (size_t i = 0; i < sets.size(); i++) {
sets[i] = make_unique<Set>();
sets[i]->add(int(i));
sets[i]->add(narrow_cast<int>(i));
}
for (size_t d = 1; d < sets.size(); d *= 2) {
for (size_t i = 0; i < sets.size(); i += 2 * d) {