Merge pull request #4 from lioncash/zero

General: Use list initialization where applicable
This commit is contained in:
Phillip Stephens 2019-09-03 00:35:57 -07:00 committed by GitHub
commit 417e79f924
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 6 deletions

View File

@ -42,11 +42,10 @@ void IPAddress::resolve(const std::string& address) noexcept {
m_valid = true; m_valid = true;
} else { } else {
/* Not a valid address, try to convert it as a host name */ /* Not a valid address, try to convert it as a host name */
addrinfo hints; addrinfo hints = {};
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
addrinfo* result = NULL; addrinfo* result = nullptr;
if (getaddrinfo(address.c_str(), NULL, &hints, &result) == 0) { if (getaddrinfo(address.c_str(), nullptr, &hints, &result) == 0) {
if (result) { if (result) {
addr = reinterpret_cast<sockaddr_in*>(result->ai_addr)->sin_addr; addr = reinterpret_cast<sockaddr_in*>(result->ai_addr)->sin_addr;
freeaddrinfo(result); freeaddrinfo(result);
@ -61,8 +60,7 @@ void IPAddress::resolve(const std::string& address) noexcept {
uint32_t IPAddress::toInteger() const noexcept { return ntohl(m_address); } uint32_t IPAddress::toInteger() const noexcept { return ntohl(m_address); }
static sockaddr_in createAddress(uint32_t address, unsigned short port) { static sockaddr_in createAddress(uint32_t address, unsigned short port) {
sockaddr_in addr; sockaddr_in addr = {};
memset(&addr, 0, sizeof(addr));
addr.sin_addr.s_addr = htonl(address); addr.sin_addr.s_addr = htonl(address);
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_port = htons(port); addr.sin_port = htons(port);