Skip to content

Commit

Permalink
Increase the level of compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
resetius committed Jul 3, 2024
1 parent e333bba commit f5367bb
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 25 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion coroio/epoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TEPoll::~TEPoll()
void TEPoll::Poll() {
auto ts = GetTimeout();

if (InEvents_.size() <= MaxFd_) {
if (static_cast<int>(InEvents_.size()) <= MaxFd_) {
InEvents_.resize(MaxFd_+1);
}

Expand Down
2 changes: 1 addition & 1 deletion coroio/poll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace NNet {
void TPoll::Poll() {
auto ts = GetTimeout();

if (InEvents_.size() <= MaxFd_) {
if (static_cast<int>(InEvents_.size()) <= MaxFd_) {
InEvents_.resize(MaxFd_+1, std::make_tuple(THandlePair{}, -1));
}

Expand Down
1 change: 0 additions & 1 deletion coroio/poller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class TPollerBase {
}

void WakeupReadyHandles() {
int i = 0;
for (auto&& ev : ReadyEvents_) {
Wakeup(std::move(ev));
}
Expand Down
18 changes: 8 additions & 10 deletions coroio/resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -132,16 +132,14 @@ void ParsePacket(uint16_t* xid, std::vector<TAddress>& 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);
Expand Down Expand Up @@ -266,7 +264,7 @@ TVoidSuspendedTask TResolver<TPoller>::ReceiverTask() {
if (size < 0) {
continue;
}
if (size < sizeof(TDnsHeader)) {
if (size < static_cast<int>(sizeof(TDnsHeader))) {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions coroio/resolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class TResolver {
std::queue<std::pair<TTime, TResolveRequest>> TimeoutsQueue;

struct TResolveResult {
std::vector<TAddress> Addresses;
std::exception_ptr Exception;
std::vector<TAddress> Addresses = {};
std::exception_ptr Exception = nullptr;
int Retries = 0;
};

Expand Down
4 changes: 2 additions & 2 deletions coroio/select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ void TSelect::Poll() {

constexpr int bits = sizeof(fd_mask)*8;

if (InEvents_.size() <= MaxFd_) {
if (static_cast<int>(InEvents_.size()) <= MaxFd_) {
InEvents_.resize(MaxFd_+1);
}
if (MaxFd_ >= ReadFds_.size()*bits) {
if (MaxFd_ >= static_cast<int>(ReadFds_.size())*bits) {
ReadFds_.resize((MaxFd_+bits)/bits);
WriteFds_.resize((MaxFd_+bits)/bits);
}
Expand Down
4 changes: 2 additions & 2 deletions coroio/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ TAddress::TAddress(sockaddr* addr, socklen_t len) {
}

int TAddress::Domain() const {
if (const auto* val = std::get_if<sockaddr_in>(&Addr_)) {
if (std::get_if<sockaddr_in>(&Addr_)) {
return PF_INET;
} else if (const auto* val = std::get_if<sockaddr_in6>(&Addr_)) {
} else if (std::get_if<sockaddr_in6>(&Addr_)) {
return PF_INET6;
} else {
return 0;
Expand Down
10 changes: 5 additions & 5 deletions coroio/socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};

Expand Down
2 changes: 1 addition & 1 deletion coroio/uring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down

0 comments on commit f5367bb

Please sign in to comment.