From f5367bb6641214a4b6b8f4716b9228b956b219fb Mon Sep 17 00:00:00 2001 From: Alexey Ozeritskiy Date: Wed, 3 Jul 2024 13:51:38 +0200 Subject: [PATCH] Increase the level of compiler warnings --- CMakeLists.txt | 6 ++++++ coroio/epoll.cpp | 2 +- coroio/poll.cpp | 2 +- coroio/poller.hpp | 1 - coroio/resolver.cpp | 18 ++++++++---------- coroio/resolver.hpp | 4 ++-- coroio/select.cpp | 4 ++-- coroio/socket.cpp | 4 ++-- coroio/socket.hpp | 10 +++++----- coroio/uring.hpp | 2 +- 10 files changed, 28 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ffd258..333bb44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,12 @@ target_include_directories(coroio PUBLIC ${URING_INCLUDE_DIRS} ${OPENSSL_INCLUDE target_link_directories(coroio PUBLIC ${URING_LIBRARY_DIRS} ${OPENSSL_LIBRARY_DIRS}) target_link_libraries(coroio PUBLIC ${URING_LIBRARIES} ${OPENSSL_LIBRARIES}) +if(MSVC) + target_compile_options(coroio PRIVATE /W4 /WX) +else() + target_compile_options(coroio PRIVATE -Wall -Wextra -Wpedantic -Werror) +endif() + macro(target name source) add_executable(${name} ${source}) target_link_libraries(${name} coroio) diff --git a/coroio/epoll.cpp b/coroio/epoll.cpp index 89d066e..40840aa 100644 --- a/coroio/epoll.cpp +++ b/coroio/epoll.cpp @@ -19,7 +19,7 @@ TEPoll::~TEPoll() void TEPoll::Poll() { auto ts = GetTimeout(); - if (InEvents_.size() <= MaxFd_) { + if (static_cast(InEvents_.size()) <= MaxFd_) { InEvents_.resize(MaxFd_+1); } diff --git a/coroio/poll.cpp b/coroio/poll.cpp index 7544a7f..7798afb 100644 --- a/coroio/poll.cpp +++ b/coroio/poll.cpp @@ -21,7 +21,7 @@ namespace NNet { void TPoll::Poll() { auto ts = GetTimeout(); - if (InEvents_.size() <= MaxFd_) { + if (static_cast(InEvents_.size()) <= MaxFd_) { InEvents_.resize(MaxFd_+1, std::make_tuple(THandlePair{}, -1)); } diff --git a/coroio/poller.hpp b/coroio/poller.hpp index f541601..9d1b877 100644 --- a/coroio/poller.hpp +++ b/coroio/poller.hpp @@ -83,7 +83,6 @@ class TPollerBase { } void WakeupReadyHandles() { - int i = 0; for (auto&& ev : ReadyEvents_) { Wakeup(std::move(ev)); } diff --git a/coroio/resolver.cpp b/coroio/resolver.cpp index 007b611..39f8c29 100644 --- a/coroio/resolver.cpp +++ b/coroio/resolver.cpp @@ -34,7 +34,7 @@ struct TDnsRecordA { uint16_t clazz; uint32_t ttl; uint16_t length; - char addr[0]; +// char addr[0]; } __attribute__((packed)); static_assert(sizeof(TDnsRecordA) == 10); @@ -132,16 +132,14 @@ void ParsePacket(uint16_t* xid, std::vector& addresses, char* buf, ssi auto addrLen = ntohs(record->length); if (addrLen == 4) { - sockaddr_in addr = { - .sin_port = 0, - .sin_addr = *(in_addr*)record->addr, - }; + sockaddr_in addr; + addr.sin_port = 0, + addr.sin_addr = *(in_addr*)(record+1); addresses.emplace_back(TAddress{addr}); } else if (addrLen == 16) { - sockaddr_in6 addr = { - .sin6_port = 0, - .sin6_addr = *(in6_addr*)record->addr - }; + sockaddr_in6 addr; + addr.sin6_port = 0, + addr.sin6_addr = *(in6_addr*)(record+1); addresses.emplace_back(TAddress{addr}); } p += sizeof(TDnsRecordA); @@ -266,7 +264,7 @@ TVoidSuspendedTask TResolver::ReceiverTask() { if (size < 0) { continue; } - if (size < sizeof(TDnsHeader)) { + if (size < static_cast(sizeof(TDnsHeader))) { continue; } diff --git a/coroio/resolver.hpp b/coroio/resolver.hpp index c4882b2..261458d 100644 --- a/coroio/resolver.hpp +++ b/coroio/resolver.hpp @@ -80,8 +80,8 @@ class TResolver { std::queue> TimeoutsQueue; struct TResolveResult { - std::vector Addresses; - std::exception_ptr Exception; + std::vector Addresses = {}; + std::exception_ptr Exception = nullptr; int Retries = 0; }; diff --git a/coroio/select.cpp b/coroio/select.cpp index 646247f..4edf1c2 100644 --- a/coroio/select.cpp +++ b/coroio/select.cpp @@ -7,10 +7,10 @@ void TSelect::Poll() { constexpr int bits = sizeof(fd_mask)*8; - if (InEvents_.size() <= MaxFd_) { + if (static_cast(InEvents_.size()) <= MaxFd_) { InEvents_.resize(MaxFd_+1); } - if (MaxFd_ >= ReadFds_.size()*bits) { + if (MaxFd_ >= static_cast(ReadFds_.size())*bits) { ReadFds_.resize((MaxFd_+bits)/bits); WriteFds_.resize((MaxFd_+bits)/bits); } diff --git a/coroio/socket.cpp b/coroio/socket.cpp index bdd2b44..a10f7da 100644 --- a/coroio/socket.cpp +++ b/coroio/socket.cpp @@ -40,9 +40,9 @@ TAddress::TAddress(sockaddr* addr, socklen_t len) { } int TAddress::Domain() const { - if (const auto* val = std::get_if(&Addr_)) { + if (std::get_if(&Addr_)) { return PF_INET; - } else if (const auto* val = std::get_if(&Addr_)) { + } else if (std::get_if(&Addr_)) { return PF_INET6; } else { return 0; diff --git a/coroio/socket.hpp b/coroio/socket.hpp index e3f7b47..361e461 100644 --- a/coroio/socket.hpp +++ b/coroio/socket.hpp @@ -144,11 +144,11 @@ class TSocketBase: public TSocketOps { } } - TPollerBase* poller; - int fd; - void* b; size_t s; - int ret; - bool ready; + TPollerBase* poller = nullptr; + int fd = -1; + void* b = nullptr; size_t s = 0; + int ret = -1; + bool ready = false; }; }; diff --git a/coroio/uring.hpp b/coroio/uring.hpp index fa4008c..2198b4d 100644 --- a/coroio/uring.hpp +++ b/coroio/uring.hpp @@ -112,7 +112,7 @@ class TUringSocket: public TSocket TUring* poller; int fd; - char addr[sizeof(sockaddr_in6)]; + char addr[sizeof(sockaddr_in6)] = {0}; socklen_t len = sizeof(sockaddr_in6); };