From eace2c242fbbcbe6badf868da71476e6c841e1ae Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Tue, 15 Jan 2019 14:56:42 +0100 Subject: [PATCH] Fix -Wextra warnings, mostly about members initialization order --- pdns/bpf-filter.cc | 27 ++++++++------ pdns/dnsdist-ecs.cc | 8 ++--- pdns/dnsdist-lua-bindings.cc | 2 +- pdns/dnspacket.cc | 70 +++++++++++++++--------------------- pdns/dnspacket.hh | 46 ++++++++++++------------ pdns/dnsrecords.cc | 1 + pdns/dnsscope.cc | 6 ++-- pdns/dynlistener.cc | 12 ++----- pdns/dynlistener.hh | 10 +++--- pdns/notify.cc | 5 ++- pdns/ssqlite3.cc | 20 +++++------ pdns/ssqlite3.hh | 2 +- pdns/ws-auth.cc | 7 ++-- pdns/ws-auth.hh | 2 +- 14 files changed, 101 insertions(+), 117 deletions(-) diff --git a/pdns/bpf-filter.cc b/pdns/bpf-filter.cc index 65cf551b3..e797a04c9 100644 --- a/pdns/bpf-filter.cc +++ b/pdns/bpf-filter.cc @@ -36,7 +36,8 @@ static __u64 ptr_to_u64(void *ptr) int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size, int max_entries) { - union bpf_attr attr = { 0 }; + union bpf_attr attr; + memset(&attr, 0, sizeof(attr)); attr.map_type = map_type; attr.key_size = key_size; attr.value_size = value_size; @@ -46,7 +47,8 @@ int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size, int bpf_update_elem(int fd, void *key, void *value, unsigned long long flags) { - union bpf_attr attr = { 0 }; + union bpf_attr attr; + memset(&attr, 0, sizeof(attr)); attr.map_fd = fd; attr.key = ptr_to_u64(key); attr.value = ptr_to_u64(value); @@ -56,7 +58,8 @@ int bpf_update_elem(int fd, void *key, void *value, unsigned long long flags) int bpf_lookup_elem(int fd, void *key, void *value) { - union bpf_attr attr = { 0 }; + union bpf_attr attr; + memset(&attr, 0, sizeof(attr)); attr.map_fd = fd; attr.key = ptr_to_u64(key); attr.value = ptr_to_u64(value); @@ -65,7 +68,8 @@ int bpf_lookup_elem(int fd, void *key, void *value) int bpf_delete_elem(int fd, void *key) { - union bpf_attr attr = { 0 }; + union bpf_attr attr; + memset(&attr, 0, sizeof(attr)); attr.map_fd = fd; attr.key = ptr_to_u64(key); return syscall(SYS_bpf, BPF_MAP_DELETE_ELEM, &attr, sizeof(attr)); @@ -73,7 +77,8 @@ int bpf_delete_elem(int fd, void *key) int bpf_get_next_key(int fd, void *key, void *next_key) { - union bpf_attr attr = { 0 }; + union bpf_attr attr; + memset(&attr, 0, sizeof(attr)); attr.map_fd = fd; attr.key = ptr_to_u64(key); attr.next_key = ptr_to_u64(next_key); @@ -85,7 +90,8 @@ int bpf_prog_load(enum bpf_prog_type prog_type, const char *license, int kern_version) { char log_buf[65535]; - union bpf_attr attr = { 0 }; + union bpf_attr attr; + memset(&attr, 0, sizeof(attr)); attr.prog_type = prog_type; attr.insns = ptr_to_u64((void *) insns); attr.insn_cnt = prog_len / sizeof(struct bpf_insn); @@ -353,8 +359,8 @@ std::vector > BPFFilter::getAddrStats() uint32_t nextV4Key; uint64_t value; int res = bpf_get_next_key(d_v4map.fd, &v4Key, &nextV4Key); - sockaddr_in v4Addr = { 0 }; - v4Addr.sin_port = 0; + sockaddr_in v4Addr; + memset(&v4Addr, 0, sizeof(v4Addr)); v4Addr.sin_family = AF_INET; while (res == 0) { @@ -369,9 +375,10 @@ std::vector > BPFFilter::getAddrStats() uint8_t v6Key[16]; uint8_t nextV6Key[16]; - sockaddr_in6 v6Addr = { 0 }; + sockaddr_in6 v6Addr; + memset(&v6Addr, 0, sizeof(v6Addr)); v6Addr.sin6_family = AF_INET6; - v6Addr.sin6_port = 0; + static_assert(sizeof(v6Addr.sin6_addr.s6_addr) == sizeof(v6Key), "POSIX mandates s6_addr to be an array of 16 uint8_t"); for (size_t idx = 0; idx < sizeof(v6Key); idx++) { v6Key[idx] = 0; diff --git a/pdns/dnsdist-ecs.cc b/pdns/dnsdist-ecs.cc index d760fd3a5..dbb6cad58 100644 --- a/pdns/dnsdist-ecs.cc +++ b/pdns/dnsdist-ecs.cc @@ -221,7 +221,7 @@ int getEDNSOptionsStart(const char* packet, const size_t offset, const size_t le } pos += 1; - uint16_t qtype = (const unsigned char)packet[pos]*256 + (const unsigned char)packet[pos+1]; + uint16_t qtype = (reinterpret_cast(packet)[pos])*256 + reinterpret_cast(packet)[pos+1]; pos += DNS_TYPE_SIZE; pos += DNS_CLASS_SIZE; @@ -669,7 +669,7 @@ bool addEDNSToQueryTurnedResponse(DNSQuestion& dq) char* optRDLen = reinterpret_cast(dq.dh) + optRDPosition; char * optPtr = (optRDLen - (/* root */ 1 + DNS_TYPE_SIZE + DNS_CLASS_SIZE + EDNS_EXTENDED_RCODE_SIZE + EDNS_VERSION_SIZE + /* Z */ 2)); - const uint8_t* zPtr = (const uint8_t*) optPtr + /* root */ 1 + DNS_TYPE_SIZE + DNS_CLASS_SIZE + EDNS_EXTENDED_RCODE_SIZE + EDNS_VERSION_SIZE; + const uint8_t* zPtr = reinterpret_cast(optPtr) + /* root */ 1 + DNS_TYPE_SIZE + DNS_CLASS_SIZE + EDNS_EXTENDED_RCODE_SIZE + EDNS_VERSION_SIZE; uint16_t z = 0x100 * (*zPtr) + *(zPtr + 1); bool dnssecOK = z & EDNS_HEADER_FLAG_DO; @@ -713,7 +713,7 @@ try pos++; - uint16_t qtype = (const unsigned char)packet[pos]*256 + (const unsigned char)packet[pos+1]; + uint16_t qtype = (reinterpret_cast(packet)[pos])*256 + reinterpret_cast(packet)[pos+1]; pos += DNS_TYPE_SIZE; pos += DNS_CLASS_SIZE; @@ -721,7 +721,7 @@ try return 0; } - const uint8_t* z = (const uint8_t*) packet + pos + EDNS_EXTENDED_RCODE_SIZE + EDNS_VERSION_SIZE; + const uint8_t* z = reinterpret_cast(packet) + pos + EDNS_EXTENDED_RCODE_SIZE + EDNS_VERSION_SIZE; return 0x100 * (*z) + *(z+1); } catch(...) diff --git a/pdns/dnsdist-lua-bindings.cc b/pdns/dnsdist-lua-bindings.cc index bec7c24bc..6444f6c45 100644 --- a/pdns/dnsdist-lua-bindings.cc +++ b/pdns/dnsdist-lua-bindings.cc @@ -233,7 +233,7 @@ void setupLuaBindings(bool client) boost::optional qtype, boost::optional suffixMatch) { if (cache) { - cache->expungeByName(dname, qtype ? *qtype : QType::ANY, suffixMatch ? *suffixMatch : false); + cache->expungeByName(dname, qtype ? *qtype : QType(QType::ANY).getCode(), suffixMatch ? *suffixMatch : false); } }); g_lua.registerFunction::*)()>("printStats", [](const std::shared_ptr cache) { diff --git a/pdns/dnspacket.cc b/pdns/dnspacket.cc index 82b3689fc..1b3bd1b19 100644 --- a/pdns/dnspacket.cc +++ b/pdns/dnspacket.cc @@ -54,25 +54,9 @@ bool DNSPacket::s_doEDNSSubnetProcessing; uint16_t DNSPacket::s_udpTruncationThreshold; -DNSPacket::DNSPacket(bool isQuery) +DNSPacket::DNSPacket(bool isQuery): d_isQuery(isQuery) { - d_wrapped=false; - d_compress=true; - d_tcp=false; - d_wantsnsid=false; - d_haveednssubnet = false; - d_dnssecOk=false; - d_ednsversion=0; - d_ednsrcode=0; memset(&d, 0, sizeof(d)); - qclass = QClass::IN; - d_tsig_algo = TSIG_MD5; - d_havetsig = false; - d_socket = -1; - d_maxreplylen = 0; - d_tsigtimersonly = false; - d_haveednssection = false; - d_isQuery = isQuery; } const string& DNSPacket::getString() @@ -94,42 +78,44 @@ uint16_t DNSPacket::getRemotePort() const } DNSPacket::DNSPacket(const DNSPacket &orig) : - d_socket(orig.d_socket), - d_remote(orig.d_remote), + d_anyLocal(orig.d_anyLocal), d_dt(orig.d_dt), - d_compress(orig.d_compress), - d_tcp(orig.d_tcp), - qtype(orig.qtype), - qclass(orig.qclass), qdomain(orig.qdomain), qdomainwild(orig.qdomainwild), qdomainzone(orig.qdomainzone), - d_maxreplylen(orig.d_maxreplylen), - d_wantsnsid(orig.d_wantsnsid), - d_anyLocal(orig.d_anyLocal), - d_eso(orig.d_eso), - d_haveednssubnet(orig.d_haveednssubnet), - d_haveednssection(orig.d_haveednssection), - d_ednsversion(orig.d_ednsversion), - d_ednsrcode(orig.d_ednsrcode), - d_dnssecOk(orig.d_dnssecOk), - d_rrs(orig.d_rrs), - d_tsigkeyname(orig.d_tsigkeyname), - d_tsigprevious(orig.d_tsigprevious), - d_tsigtimersonly(orig.d_tsigtimersonly), + d(orig.d), d_trc(orig.d_trc), - d_tsigsecret(orig.d_tsigsecret), + d_remote(orig.d_remote), + d_tsig_algo(orig.d_tsig_algo), + d_ednsRawPacketSizeLimit(orig.d_ednsRawPacketSizeLimit), + qclass(orig.qclass), + qtype(orig.qtype), + d_tcp(orig.d_tcp), + d_dnssecOk(orig.d_dnssecOk), d_havetsig(orig.d_havetsig), - d_wrapped(orig.d_wrapped), + d_tsigsecret(orig.d_tsigsecret), + d_tsigkeyname(orig.d_tsigkeyname), + d_tsigprevious(orig.d_tsigprevious), + d_rrs(orig.d_rrs), d_rawpacket(orig.d_rawpacket), - d_tsig_algo(orig.d_tsig_algo), - d(orig.d), + d_eso(orig.d_eso), + d_maxreplylen(orig.d_maxreplylen), + d_socket(orig.d_socket), + d_hash(orig.d_hash), + d_ednsrcode(orig.d_ednsrcode), + d_ednsversion(orig.d_ednsversion), + + d_wrapped(orig.d_wrapped), + d_compress(orig.d_compress), + d_tsigtimersonly(orig.d_tsigtimersonly), + d_wantsnsid(orig.d_wantsnsid), + d_haveednssubnet(orig.d_haveednssubnet), + d_haveednssection(orig.d_haveednssection), - d_isQuery(orig.d_isQuery), - d_hash(orig.d_hash) + d_isQuery(orig.d_isQuery) { DLOG(g_log<<"DNSPacket copy constructor called!"<& getRRS() { return d_rrs; } bool checkForCorrectTSIG(UeberBackend* B, DNSName* keyname, string* secret, TSIGRecordContent* trc) const; - static bool s_doEDNSSubnetProcessing; static uint16_t s_udpTruncationThreshold; - int d_ednsRawPacketSizeLimit; // only used for Lua record + static bool s_doEDNSSubnetProcessing; + private: void pasteQ(const char *question, int length); //!< set the question of this packet, useful for crafting replies - bool d_wrapped; // 1 - int d_socket; // 4 - string d_tsigsecret; DNSName d_tsigkeyname; string d_tsigprevious; @@ -179,19 +177,19 @@ private: string d_rawpacket; // this is where everything lives 8 EDNSSubnetOpts d_eso; - int d_maxreplylen; - - uint8_t d_ednsversion; - // WARNING! This is really 12 bits - uint16_t d_ednsrcode; - + int d_maxreplylen{0}; + int d_socket{-1}; // 4 uint32_t d_hash{0}; - - bool d_compress; // 1 - bool d_tsigtimersonly; - bool d_wantsnsid; - bool d_haveednssubnet; - bool d_haveednssection; + // WARNING! This is really 12 bits + uint16_t d_ednsrcode{0}; + uint8_t d_ednsversion{0}; + + bool d_wrapped{false}; // 1 + bool d_compress{true}; // 1 + bool d_tsigtimersonly{false}; + bool d_wantsnsid{false}; + bool d_haveednssubnet{false}; + bool d_haveednssection{false}; bool d_isQuery; }; diff --git a/pdns/dnsrecords.cc b/pdns/dnsrecords.cc index 4109a70c6..c29f1794d 100644 --- a/pdns/dnsrecords.cc +++ b/pdns/dnsrecords.cc @@ -34,6 +34,7 @@ void DNSResourceRecord::setContent(const string &cont) { case QType::MX: if (content.size() >= 2 && *(content.rbegin()+1) == ' ') return; + /* Falls through. */ case QType::CNAME: case QType::DNAME: case QType::NS: diff --git a/pdns/dnsscope.cc b/pdns/dnsscope.cc index 8e46b4b78..4395898c1 100644 --- a/pdns/dnsscope.cc +++ b/pdns/dnsscope.cc @@ -355,9 +355,9 @@ try // cout<<"Clearing state for "<