Skip to content

Commit

Permalink
Add -Wconversion
Browse files Browse the repository at this point in the history
  • Loading branch information
durner committed Feb 14, 2024
1 parent ab4be80 commit 1eaf36e
Show file tree
Hide file tree
Showing 29 changed files with 181 additions and 139 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fuse-ld=lld")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld")

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address,undefined -Wall -Wextra -Wold-style-cast -Woverloaded-virtual -Wmissing-declarations -Wno-unqualified-std-cast-call -Wvla -Werror")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -march=native -Wall -Wextra -Wold-style-cast -Woverloaded-virtual -Wmissing-declarations -Wno-unqualified-std-cast-call -Wvla -Werror")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -march=native -Wall -Wextra -Wold-style-cast -Woverloaded-virtual -Wmissing-declarations -Wno-unqualified-std-cast-call -Wvla -Werror")
set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -Wold-style-cast -Woverloaded-virtual -Wmissing-declarations -Wno-unqualified-std-cast-call -Wvla -Werror -coverage")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address,undefined -Wall -Wextra -Wold-style-cast -Woverloaded-virtual -Wmissing-declarations -Wno-unqualified-std-cast-call -Wvla -Wconversion -Werror")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -march=native -Wall -Wextra -Wold-style-cast -Woverloaded-virtual -Wmissing-declarations -Wno-unqualified-std-cast-call -Wvla -Wconversion -Werror")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -march=native -Wall -Wextra -Wold-style-cast -Woverloaded-virtual -Wmissing-declarations -Wno-unqualified-std-cast-call -Wvla -Wconversion -Werror")
set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -Wold-style-cast -Woverloaded-virtual -Wmissing-declarations -Wno-unqualified-std-cast-call -Wvla -Wconversion -Werror -coverage")

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
# Default to Release build type, similar to Makefile
Expand Down
2 changes: 1 addition & 1 deletion include/cloud/aws.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AWS : public Provider {
/// The custom endpoint
std::string endpoint;
/// The port
int port = 80;
uint32_t port = 80;
};

/// The secret
Expand Down
2 changes: 1 addition & 1 deletion include/cloud/aws_resolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace cloud {
/// Implements the AWS Resolver logic
class AWSResolver : public network::Resolver {
/// The good mtu cache
std::unordered_map<int, bool> _mtuCache;
std::unordered_map<unsigned, bool> _mtuCache;

public:
/// The constructor
Expand Down
2 changes: 1 addition & 1 deletion include/cloud/azure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Azure : public Provider {
/// The container name
std::string container;
/// The port
int port;
uint32_t port;
};

/// The secret
Expand Down
2 changes: 1 addition & 1 deletion include/cloud/gcp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GCP : public Provider {
/// The gcp region
std::string region;
/// The gcp port
int port;
uint32_t port;
};

/// The secret
Expand Down
2 changes: 1 addition & 1 deletion include/cloud/provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Provider {
/// The endpoint
std::string endpoint = "";
/// The port
int port = 80;
uint32_t port = 80;
};

/// Instance struct
Expand Down
4 changes: 2 additions & 2 deletions include/network/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ struct Config {
constexpr auto bandwidth() const { return network; }
/// Get the number of requests per core
constexpr auto coreRequests() const { return coreConcurreny; }
/// Get the number of retriever threads to saturate bandwidth
constexpr auto retrievers() const { return (network + coreThroughput - 1) / coreThroughput; }
/// Get the total outstanding requests
constexpr auto totalRequests() const { return retrievers() * coreRequests(); }
/// Get the number of retriever threads to saturate bandwidth
constexpr unsigned retrievers() const { return std::ceil(static_cast<double>(network) / coreThroughput); }
};
//---------------------------------------------------------------------------
} // namespace network
Expand Down
8 changes: 4 additions & 4 deletions include/network/io_uring_socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ class IOUringSocket {
void addResolver(const std::string& hostname, std::unique_ptr<Resolver> resolver);

/// Prepare a submission (sqe) send
io_uring_sqe* send_prep(const Request* req, int32_t msg_flags = 0, int32_t flags = 0);
io_uring_sqe* send_prep(const Request* req, int32_t msg_flags = 0, uint8_t flags = 0);
/// Prepare a submission (sqe) recv
io_uring_sqe* recv_prep(Request* req, int32_t msg_flags = 0, int32_t flags = 0);
io_uring_sqe* recv_prep(Request* req, int32_t msg_flags = 0, uint8_t flags = 0);
/// Prepare a submission (sqe) send with timeout
io_uring_sqe* send_prep_to(const Request* req, __kernel_timespec* timeout, int32_t msg_flags = 0, int32_t flags = 0);
io_uring_sqe* send_prep_to(const Request* req, __kernel_timespec* timeout, int32_t msg_flags = 0, uint8_t flags = 0);
/// Prepare a submission (sqe) recv with timeout
io_uring_sqe* recv_prep_to(Request* req, __kernel_timespec* timeout, int32_t msg_flags = 0, int32_t flags = 0);
io_uring_sqe* recv_prep_to(Request* req, __kernel_timespec* timeout, int32_t msg_flags = 0, uint8_t flags = 0);

/// Submits queue and gets all completion (cqe) event and mark them as seen; return the SQE attached requests
uint32_t submitCompleteAll(uint32_t events, std::vector<IOUringSocket::Request*>& completions);
Expand Down
10 changes: 5 additions & 5 deletions include/network/resolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ class Resolver {
/// The addr info
std::vector<std::unique_ptr<addrinfo, decltype(&freeaddrinfo)>> _addr;
/// The current addr string
std::vector<std::pair<std::string, int>> _addrString;
std::vector<std::pair</*addrAndPort=*/std::string, /*cacheCtr=*/int>> _addrString;
/// The ctr
uint64_t _addrCtr;
unsigned _addrCtr;

public:
/// The constructor
explicit Resolver(unsigned entries);
/// The address resolving
virtual unsigned resolve(std::string hostname, std::string port, bool& oldAddress);
/// Increment the addr ctr
virtual void increment() { _addrCtr++; }
void increment() { _addrCtr++; }
/// Erase the current cache
virtual void erase() { _addrString[_addrCtr % _addrString.size()].second = 0; }
void erase() { _addrString[_addrCtr % _addrString.size()].second = 0; }
/// Start the timing
virtual void startSocket(int /*fd*/, unsigned /*ipAsInt*/) {}
/// Stop the timing
Expand All @@ -48,7 +48,7 @@ class Resolver {
virtual ~Resolver() noexcept = default;

/// Get the tld
static std::string_view tld(std::string const& domain);
static std::string_view tld(std::string_view domain);

friend IOUringSocket;
};
Expand Down
8 changes: 4 additions & 4 deletions include/network/tasked_send_receiver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class TaskedSendReceiverGroup {
/// The recv chunk size
uint64_t _chunkSize;
/// The queue maximum for each TaskedSendReceiver
uint64_t _concurrentRequests;
unsigned _concurrentRequests;

/// Condition variable to stop wasting wait cycles
std::condition_variable _cv;
Expand All @@ -64,7 +64,7 @@ class TaskedSendReceiverGroup {

public:
/// Initializes the global submissions and completions
TaskedSendReceiverGroup(uint64_t chunkSize = 64u * 1024, uint64_t submissions = std::thread::hardware_concurrency() * submissionPerCore, uint64_t reuse = 0);
TaskedSendReceiverGroup(unsigned chunkSize = 64u * 1024, uint64_t submissions = std::thread::hardware_concurrency() * submissionPerCore, uint64_t reuse = 0);
/// Destructor
~TaskedSendReceiverGroup();

Expand All @@ -83,12 +83,12 @@ class TaskedSendReceiverGroup {
_concurrentRequests = config.coreRequests();
}
/// Update the concurrent requests
void setConcurrentRequests(uint64_t concurrentRequests) {
void setConcurrentRequests(unsigned concurrentRequests) {
if (_concurrentRequests != concurrentRequests)
_concurrentRequests = concurrentRequests;
}
/// Get the concurrent requests
uint64_t getConcurrentRequests() const {
unsigned getConcurrentRequests() const {
return _concurrentRequests;
}

Expand Down
14 changes: 7 additions & 7 deletions include/network/tls_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ class TLSConnection {
/// The state
struct State {
/// Bytes wanted to write from internal bio (used for send)
int internalBioWrite;
size_t internalBioWrite;
/// Bytes read from network bio (used for send)
int networkBioRead;
int64_t networkBioRead;
/// Bytes written to socket (used for send)
int socketWrite;
size_t socketWrite;
/// Bytes wanted to read from internal bio (used for recv)
int internalBioRead;
// Bytes written to network bio (used for recv)
int networkBioWrite;
size_t internalBioRead;
/// Bytes written to network bio (used for recv)
int64_t networkBioWrite;
/// Bytes read fromsocket (used for recv)
int socketRead;
size_t socketRead;
/// The progress
Progress progress;

Expand Down
8 changes: 4 additions & 4 deletions include/network/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ class Transaction {
/// The state
std::atomic<State> state;
/// The error message id
std::atomic<int> errorMessageId;
std::atomic<uint64_t> errorMessageId;

/// The constructor
explicit MultipartUpload(int parts) : messages(parts + 1), eTags(parts), outstanding(parts), state(State::Default) {}
explicit MultipartUpload(uint16_t parts) : messages(parts + 1), eTags(parts), outstanding(static_cast<int>(parts)), state(State::Default) {}
/// Copy constructor
MultipartUpload(MultipartUpload& other) = delete;
/// Move constructor
Expand Down Expand Up @@ -167,7 +167,7 @@ class Transaction {
inline void putObjectRequestMultiPart(Callback&& callback, const std::string& remotePath, const char* data, uint64_t size, uint8_t* result = nullptr, uint64_t capacity = 0, uint64_t traceId = 0) {
assert(_provider);
auto splitSize = _provider->multipartUploadSize();
auto parts = (size / splitSize) + ((size % splitSize) ? 1u : 0u);
uint16_t parts = static_cast<uint16_t>((size / splitSize) + ((size % splitSize) ? 1u : 0u));
_multipartUploads.emplace_back(parts);
auto position = _multipartUploads.size() - 1;

Expand All @@ -178,7 +178,7 @@ class Transaction {
}
_multipartUploads[position].uploadId = _provider->getUploadId(initalRequestResult.getResult());
auto offset = 0ull;
for (auto i = 1ull; i <= parts; i++) {
for (uint16_t i = 1; i <= parts; i++) {
auto finishMultipart = [&callback, &initalRequestResult, position, remotePath, traceId, i, parts, this](network::MessageResult& result) {
if (!result.success()) [[unlikely]] {
_multipartUploads[position].errorMessageId = i - 1;
Expand Down
16 changes: 9 additions & 7 deletions include/utils/data_vector.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <cassert>
#include <cstdint>
#include <cstring>
#include <memory>
Expand Down Expand Up @@ -45,7 +46,8 @@ class DataVector {

/// Constructor from other pointers
constexpr DataVector(T* start, T* end) : _capacity(0), _size(0) {
resize(end - start);
assert(end - start >= 0);
resize(static_cast<uint64_t>(end - start));
std::memcpy(data(), start, size() * sizeof(T));
}

Expand All @@ -55,22 +57,22 @@ class DataVector {
}

/// Get the data
[[ nodiscard ]] constexpr T* data() {
[[nodiscard]] constexpr T* data() {
return _data;
}

/// Get the data
[[ nodiscard ]] constexpr const T* cdata() const {
[[nodiscard]] constexpr const T* cdata() const {
return _data;
}

/// Get the size
[[ nodiscard ]] constexpr uint64_t size() const {
[[nodiscard]] constexpr uint64_t size() const {
return _size;
}

/// Get the capacity
[[ nodiscard ]] constexpr uint64_t capacity() const {
[[nodiscard]] constexpr uint64_t capacity() const {
return _capacity;
}

Expand All @@ -80,7 +82,7 @@ class DataVector {
}

/// Is the data owned
[[ nodiscard ]] constexpr bool owned() {
[[nodiscard]] constexpr bool owned() {
return _dataOwned || !_capacity;
}

Expand All @@ -107,7 +109,7 @@ class DataVector {
}

/// Transfer the ownership of the data
[[ nodiscard ]] constexpr std::unique_ptr<T[]> transferBuffer() {
[[nodiscard]] constexpr std::unique_ptr<T[]> transferBuffer() {
return move(_dataOwned);
}
};
Expand Down
14 changes: 7 additions & 7 deletions src/cloud/aws_resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ AWSResolver::AWSResolver(unsigned entries) : Resolver(entries), _mtuCache()
unsigned AWSResolver::resolve(string hostname, string port, bool& oldAddress)
// Resolve the request
{
auto addrPos = _addrCtr % _addrString.size();
auto addrPos = _addrCtr % static_cast<unsigned>(_addrString.size());
auto curCtr = _addrString[addrPos].second--;
auto hostString = hostname + ":" + port;
// Reuses old address
Expand All @@ -45,13 +45,13 @@ unsigned AWSResolver::resolve(string hostname, string port, bool& oldAddress)
_addr[addrPos].reset(temp);
if (!Resolver::tld(hostname).compare("amazonaws.com")) {
struct sockaddr_in* p = reinterpret_cast<sockaddr_in*>(_addr[addrPos]->ai_addr);
int ipAsInt = p->sin_addr.s_addr;
auto ipAsInt = p->sin_addr.s_addr;
auto it = _mtuCache.find(ipAsInt);
if (it != _mtuCache.end()) {
if (it->second)
_addrString[addrPos] = {hostString, numeric_limits<int>::max()};
_addrString[addrPos] = {move(hostString), numeric_limits<int>::max()};
else
_addrString[addrPos] = {hostString, 12};
_addrString[addrPos] = {move(hostString), 12};
} else {
char ipv4[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &p->sin_addr, ipv4, INET_ADDRSTRLEN);
Expand All @@ -60,14 +60,14 @@ unsigned AWSResolver::resolve(string hostname, string port, bool& oldAddress)
auto res = system(cmd.c_str());
if (!res) {
_mtuCache.emplace(ipAsInt, true);
_addrString[addrPos] = {hostString, numeric_limits<int>::max()};
_addrString[addrPos] = {move(hostString), numeric_limits<int>::max()};
} else {
_mtuCache.emplace(ipAsInt, false);
_addrString[addrPos] = {hostString, 12};
_addrString[addrPos] = {move(hostString), 12};
}
}
} else {
_addrString[addrPos] = {hostString, 12};
_addrString[addrPos] = {move(hostString), 12};
}
oldAddress = false;
}
Expand Down
4 changes: 3 additions & 1 deletion src/cloud/provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ Provider::RemoteInfo Provider::getRemoteInfo(const string& fileName) {
auto addressPort = sub.substr(0, pos);
if (auto colonPos = addressPort.find(':'); colonPos != string::npos) {
info.endpoint = addressPort.substr(0, colonPos);
info.port = atoi(addressPort.substr(colonPos + 1).c_str());
auto port = atoi(addressPort.substr(colonPos + 1).c_str());
assert(port > 0);
info.port = static_cast<unsigned>(port);
} else {
info.endpoint = addressPort;
info.port = 80;
Expand Down
43 changes: 26 additions & 17 deletions src/network/http_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,48 @@ using namespace std;
HTTPHelper::Info HTTPHelper::detect(string_view header)
// Detect the protocol
{
auto info = Info{0, 0, Protocol::Unknown, Encoding::Unknown};
static constexpr auto unknown = Info{0, 0, Protocol::Unknown, Encoding::Unknown};
Info info = unknown;

string str_http_1_0 = "HTTP/1.0 200 OK";
string str_http_1_1 = "HTTP/1.1 200 OK";
string str_http_1_1_partial = "HTTP/1.1 206 Partial Content";
string str_http_1_1_created = "HTTP/1.1 201 Created";
string str_http_1_1_no_conent = "HTTP/1.1 204 No Content";

if (header.length() >= str_http_1_0.size() && !strncmp(header.data(), str_http_1_0.c_str(), str_http_1_0.size()))
static constexpr string_view str_http_1_0 = "HTTP/1.0 200 OK";
static constexpr string_view str_http_1_1 = "HTTP/1.1 200 OK";
static constexpr string_view str_http_1_1_partial = "HTTP/1.1 206 Partial Content";
static constexpr string_view str_http_1_1_created = "HTTP/1.1 201 Created";
static constexpr string_view str_http_1_1_no_content = "HTTP/1.1 204 No Content";
if (header.starts_with(str_http_1_0)) {
info.protocol = Protocol::HTTP_1_0_OK;
else if (header.length() >= str_http_1_1.size() && !strncmp(header.data(), str_http_1_1.c_str(), str_http_1_1.size()))
} else if (header.starts_with(str_http_1_1)) {
info.protocol = Protocol::HTTP_1_1_OK;
else if (header.length() >= str_http_1_1_partial.size() && !strncmp(header.data(), str_http_1_1_partial.c_str(), str_http_1_1_partial.size()))
} else if (header.starts_with(str_http_1_1_partial)) {
info.protocol = Protocol::HTTP_1_1_Partial;
else if (header.length() >= str_http_1_1_created.size() && !strncmp(header.data(), str_http_1_1_created.c_str(), str_http_1_1_created.size()))
} else if (header.starts_with(str_http_1_1_created)) {
info.protocol = Protocol::HTTP_1_1_Created;
else if (header.length() >= str_http_1_1_no_conent.size() && !strncmp(header.data(), str_http_1_1_no_conent.c_str(), str_http_1_1_no_conent.size()))
} else if (header.starts_with(str_http_1_1_no_content)) {
info.protocol = Protocol::HTTP_1_1_No_Content;
}

static constexpr string_view chunkedEncoding = "Transfer-Encoding: chunked";
static constexpr string_view contentLength = "Content-Length: ";
static constexpr string_view headerEnd = "\r\n\r\n";

if (info.protocol != Protocol::Unknown) {
if (header.npos != header.find("Transfer-Encoding: chunked")) {
if (header.find(chunkedEncoding) != string_view::npos) {
info.encoding = Encoding::ChunkedEncoding;
info.headerLength = header.find("\r\n\r\n"sv) + 4;
auto end = header.find(headerEnd);
if (end == string_view::npos) return unknown;
info.headerLength = static_cast<unsigned>(end) + static_cast<unsigned>(headerEnd.length());
} else {
string contentLength = "Content-Length: ";
auto pos = header.find(contentLength);
if (header.npos != pos) {
if (pos != string_view::npos) {
auto end = header.find("\r\n", pos);
if (end == string_view::npos) return unknown;
auto strSize = header.substr(pos + contentLength.size(), end - pos);
info.encoding = Encoding::ContentLength;
from_chars(strSize.data(), strSize.data() + strSize.size(), info.length);
}
info.headerLength = header.find("\r\n\r\n"sv) + 4;
auto end = header.find(headerEnd);
if (end == string_view::npos) return unknown;
info.headerLength = static_cast<unsigned>(end) + static_cast<unsigned>(headerEnd.length());
}
}

Expand Down
Loading

0 comments on commit 1eaf36e

Please sign in to comment.