Codechange: use value initialisation over memset
This commit is contained in:
@@ -202,8 +202,7 @@ bool NetworkAddress::IsInNetmask(std::string_view netmask)
|
||||
SOCKET NetworkAddress::Resolve(int family, int socktype, int flags, SocketList *sockets, LoopProc func)
|
||||
{
|
||||
struct addrinfo *ai;
|
||||
struct addrinfo hints;
|
||||
memset(&hints, 0, sizeof (hints));
|
||||
struct addrinfo hints{};
|
||||
hints.ai_family = family;
|
||||
hints.ai_flags = flags;
|
||||
hints.ai_socktype = socktype;
|
||||
|
||||
@@ -27,10 +27,10 @@ using SocketList = std::map<SOCKET, NetworkAddress>; ///< Type for a mapping
|
||||
*/
|
||||
class NetworkAddress {
|
||||
private:
|
||||
std::string hostname; ///< The hostname
|
||||
int address_length; ///< The length of the resolved address
|
||||
sockaddr_storage address; ///< The resolved address
|
||||
bool resolved; ///< Whether the address has been (tried to be) resolved
|
||||
std::string hostname{}; ///< The hostname
|
||||
int address_length{}; ///< The length of the resolved address
|
||||
sockaddr_storage address{}; ///< The resolved address
|
||||
bool resolved = false; ///< Whether the address has been (tried to be) resolved
|
||||
|
||||
/**
|
||||
* Helper function to resolve something to a socket.
|
||||
@@ -62,7 +62,6 @@ public:
|
||||
address_length(address_length),
|
||||
resolved(address_length != 0)
|
||||
{
|
||||
memset(&this->address, 0, sizeof(this->address));
|
||||
memcpy(&this->address, address, address_length);
|
||||
}
|
||||
|
||||
@@ -81,8 +80,6 @@ public:
|
||||
hostname.remove_suffix(1);
|
||||
}
|
||||
this->hostname = hostname;
|
||||
|
||||
memset(&this->address, 0, sizeof(this->address));
|
||||
this->address.ss_family = family;
|
||||
this->SetPort(port);
|
||||
}
|
||||
|
||||
@@ -222,8 +222,7 @@ void TCPConnecter::Resolve()
|
||||
/* Port is already guaranteed part of the connection_string. */
|
||||
NetworkAddress address = ParseConnectionString(this->connection_string, 0);
|
||||
|
||||
addrinfo hints;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
addrinfo hints{};
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_flags = AI_ADDRCONFIG;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
|
||||
@@ -76,8 +76,7 @@ public:
|
||||
static void AcceptClient(SOCKET ls)
|
||||
{
|
||||
for (;;) {
|
||||
struct sockaddr_storage sin;
|
||||
memset(&sin, 0, sizeof(sin));
|
||||
struct sockaddr_storage sin{};
|
||||
socklen_t sin_len = sizeof(sin);
|
||||
SOCKET s = accept(ls, (struct sockaddr*)&sin, &sin_len);
|
||||
if (s == INVALID_SOCKET) return;
|
||||
|
||||
@@ -113,8 +113,7 @@ void NetworkUDPSocketHandler::ReceivePackets()
|
||||
{
|
||||
for (auto &s : this->sockets) {
|
||||
for (int i = 0; i < 1000; i++) { // Do not infinitely loop when DoSing with UDP
|
||||
struct sockaddr_storage client_addr;
|
||||
memset(&client_addr, 0, sizeof(client_addr));
|
||||
struct sockaddr_storage client_addr{};
|
||||
|
||||
/* The limit is UDP_MTU, but also allocate that much as we need to read the whole packet in one go. */
|
||||
Packet p(this, UDP_MTU, UDP_MTU);
|
||||
|
||||
Reference in New Issue
Block a user