]> granicus.if.org Git - pdns/commitdiff
Fix warnings reported by GCC 8.1.0
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 9 May 2018 15:06:40 +0000 (17:06 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 9 May 2018 15:06:40 +0000 (17:06 +0200)
- polymorphic exceptions caught by value
- ComboAddress objects manipulated via `memset()`

13 files changed:
modules/remotebackend/remotebackend.hh
pdns/communicator.hh
pdns/dbdnsseckeeper.cc
pdns/dnsdist-tcp.cc
pdns/dnsrecords.cc
pdns/ednssubnet.cc
pdns/iputils.cc
pdns/iputils.hh
pdns/misc.cc
pdns/nameserver.cc
pdns/pdns_recursor.cc
pdns/syncres.hh
pdns/test-iputils_hh.cc

index 31805947c230a1787987dd4aa24802fac48e84c7..9690f6f933295d3604fe0025d3b6a221f4ba541e 100644 (file)
@@ -215,7 +215,7 @@ class RemoteBackend : public DNSBackend
         string val = asString(value);
         if (val == "0") return false;
         if (val == "1") return true;
-      } catch (JsonException) {};
+      } catch (const JsonException&) {};
       throw JsonException("Json value not convertible to boolean");
     };
 
index f853e69ae540442fe35bbadd58f316edd69e8f4e..087a3dbc5803be32b77ae19fec59a78596f8a2c1 100644 (file)
@@ -282,7 +282,7 @@ private:
         struct addrinfo* address = res;
         do {
           if (address->ai_addrlen <= sizeof(remote)) {
-            memcpy(&remote, address->ai_addr, address->ai_addrlen);
+            remote.setSockaddr(address->ai_addr, address->ai_addrlen);
             addresses->push_back(remote.toString());
           }
         } while((address = address->ai_next));
index 415a5d07ac2aa1e78642e4f49354e4b71bdf17c9..b34d23164bdfc2242fe58a4b566efd3b088a5f63 100644 (file)
@@ -100,7 +100,7 @@ bool DNSSECKeeper::addKey(const DNSName& name, bool setSEPBit, int algorithm, in
   shared_ptr<DNSCryptoKeyEngine> dpk(DNSCryptoKeyEngine::make(algorithm));
   try{
     dpk->create(bits);
-  } catch (std::runtime_error error){
+  } catch (const std::runtime_error& error){
     throw runtime_error("The algorithm does not support the given bit size.");
   }
   dspk.setKey(dpk);
index b94fb6b981e90d302c70cd6f89f804c8e33df388..0eb7ea1396ec2dc2c45c01ff31949d4d770d77fa 100644 (file)
@@ -267,7 +267,7 @@ void* tcpClientThread(int pipefd)
     vector<uint8_t> rewrittenResponse;
     shared_ptr<DownstreamState> ds;
     ComboAddress dest;
-    memset(&dest, 0, sizeof(dest));
+    dest.reset();
     dest.sin4.sin_family = ci.remote.sin4.sin_family;
     socklen_t len = dest.getSocklen();
     size_t queriesCount = 0;
index 457a78331a526dab274eb738a481b6787fd98473..298f2755333db5c52cd3ad0fdc2d3a5964d691e3 100644 (file)
@@ -117,7 +117,7 @@ ComboAddress ARecordContent::getCA(int port) const
 ComboAddress AAAARecordContent::getCA(int port) const
 {
   ComboAddress ret;
-  memset(&ret, 0, sizeof(ret));
+  ret.reset();
 
   ret.sin4.sin_family=AF_INET6;
   ret.sin6.sin6_port = htons(port);
index 4528be3f3c6f947fc43edf591d3f2f96834e4ac0..4826f602f2e98a98d9866ef3a35ed739f1ec7e96 100644 (file)
@@ -57,7 +57,7 @@ bool getEDNSSubnetOptsFromString(const char* options, unsigned int len, EDNSSubn
       return false;
     if(octetsin > sizeof(address.sin4.sin_addr.s_addr))
       return false;
-    memset(&address, 0, sizeof(address));
+    address.reset();
     address.sin4.sin_family = AF_INET;
     if(octetsin > 0)
       memcpy(&address.sin4.sin_addr.s_addr, options+sizeof(esow), octetsin);
@@ -66,7 +66,8 @@ bool getEDNSSubnetOptsFromString(const char* options, unsigned int len, EDNSSubn
       return false;
     if(octetsin > sizeof(address.sin6.sin6_addr.s6_addr))
       return false;
-    memset(&address, 0, sizeof(address));
+
+    address.reset();
     address.sin4.sin_family = AF_INET6;
     if(octetsin > 0)
       memcpy(&address.sin6.sin6_addr.s6_addr, options+sizeof(esow), octetsin);
index b3d44f353acdaef483c971a4d0c439d81b699988..daf5997d6f465acafe15de29f361caa02ee31a97 100644 (file)
@@ -153,7 +153,7 @@ bool HarvestTimestamp(struct msghdr* msgh, struct timeval* tv)
 }
 bool HarvestDestinationAddress(const struct msghdr* msgh, ComboAddress* destination)
 {
-  memset(destination, 0, sizeof(*destination));
+  destination->reset();
 #ifdef __NetBSD__
   struct cmsghdr* cmsg;
 #else
index 5c152327ae010ac57d0544b27fc79c88f78af25f..4762c249e7c103dc77cd054397837425de28e610 100644 (file)
@@ -313,6 +313,12 @@ union ComboAddress {
     return ret;
   }
 
+  void reset()
+  {
+    memset(&sin4, 0, sizeof(sin4));
+    memset(&sin6, 0, sizeof(sin6));
+  }
+
 };
 
 /** This exception is thrown by the Netmask class and by extension by the NetmaskGroup class */
index 219d0e003431bc85bee79c543b2a7f7a4d04cf36..6efb3f6da0ef7c970b5480a48d98912023c38deb 100644 (file)
@@ -765,7 +765,7 @@ int makeIPv6sockaddr(const std::string& addr, struct sockaddr_in6* ret)
         port = pdns_stou(addr.substr(pos+2));
         portSet = true;
       }
-      catch(std::out_of_range) {
+      catch(const std::out_of_range&) {
         return -1;
       }
     }
index bfcf5646ea14d57634edd553cf157e06708770bd..ef7eef4c66d603bd87488ba37ecd4cafb11df803 100644 (file)
@@ -111,8 +111,8 @@ void UDPNameserver::bindIPv4()
   
     if(!setNonBlocking(s))
       throw PDNSException("Unable to set UDP socket to non-blocking: "+stringerror());
-  
-    memset(&locala,0,sizeof(locala));
+
+    locala.reset();
     locala.sin4.sin_family=AF_INET;
 
     if(localname=="0.0.0.0")
index 78c85174ec8335c9dae7809db1c9e37e32f40888..89aaa7db204f5c18631b85c524dbf5e7cf1b44ef 100644 (file)
@@ -1624,7 +1624,7 @@ static void handleRunningTCPQuestion(int fd, FDMultiplexer::funcparam_t& var)
       dc->setRemote(conn->d_remote);
       dc->setSource(conn->d_remote);
       ComboAddress dest;
-      memset(&dest, 0, sizeof(dest));
+      dest.reset();
       dest.sin4.sin_family = conn->d_remote.sin4.sin_family;
       socklen_t len = dest.getSocklen();
       getsockname(conn->getFD(), (sockaddr*)&dest, &len); // if this fails, we're ok with it
@@ -2045,7 +2045,7 @@ static void handleNewUDPQuestion(int fd, FDMultiplexer::funcparam_t& var)
        struct timeval tv={0,0};
        HarvestTimestamp(&msgh, &tv);
        ComboAddress dest;
-       memset(&dest, 0, sizeof(dest)); // this makes sure we ignore this address if not returned by recvmsg above
+       dest.reset(); // this makes sure we ignore this address if not returned by recvmsg above
         auto loc = rplookup(g_listenSocketsAddresses, fd);
        if(HarvestDestinationAddress(&msgh, &dest)) {
           // but.. need to get port too
@@ -2104,7 +2104,7 @@ static void makeTCPServerSockets(unsigned int threadId)
 
     ComboAddress sin;
 
-    memset((char *)&sin,0, sizeof(sin));
+    sin.reset();
     sin.sin4.sin_family = AF_INET;
     if(!IpToU32(st.host, (uint32_t*)&sin.sin4.sin_addr.s_addr)) {
       sin.sin6.sin6_family = AF_INET6;
@@ -2190,7 +2190,7 @@ static void makeUDPServerSockets(unsigned int threadId)
 
     ComboAddress sin;
 
-    memset(&sin, 0, sizeof(sin));
+    sin.reset();
     sin.sin4.sin_family = AF_INET;
     if(!IpToU32(st.host.c_str() , (uint32_t*)&sin.sin4.sin_addr.s_addr)) {
       sin.sin6.sin6_family = AF_INET6;
index b10b440761a73177ba733b89821f9f0f116c0a7c..ac528fa2d35575a876c2a911cbcf097ec8bbf642 100644 (file)
@@ -831,7 +831,7 @@ struct PacketID
 {
   PacketID() : id(0), type(0), sock(0), inNeeded(0), inIncompleteOkay(false), outPos(0), nearMisses(0), fd(-1)
   {
-    memset(&remote, 0, sizeof(remote));
+    remote.reset();
   }
 
   uint16_t id;  // wait for a specific id/remote pair
index a9edbcb3a858edf7287fa71efba794a68aacfcb4..44e1478d7ab1a2188ef5d450a302dec0237c3301 100644 (file)
@@ -69,8 +69,8 @@ BOOST_AUTO_TEST_CASE(test_ComboAddress) {
 
 BOOST_AUTO_TEST_CASE(test_ComboAddressCompare) {
   ComboAddress a, b;
-  memset(&a, 0, sizeof(a));
-  memset(&b, 0, sizeof(b));
+  a.reset();
+  b.reset();
   BOOST_CHECK(!(a<b));
   BOOST_CHECK(!(a>b));
 }