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

(cherry picked from commit d38e2ba97a78aa9dfc894fc4e13a6f3a410dd31a)

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 b44af82c98c27d5a08b36795c1bdb9148093e70e..c91e648372161110a90ba0f0a373dd9afa1780d5 100644 (file)
@@ -216,7 +216,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 8d842aa6d8bd657adeebd2d82d784bfba5a1813f..a7f95b81da31fe154794e02072987abaa6323e15 100644 (file)
@@ -275,7 +275,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 d006bac02a87d647548ad2f7b6128682ceef3317..1af88637d24fd1ef0f39e0d00929a30b0ed8e9b0 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 e74ac4a398763d99b4fa14e85a6ca2993eaf7b3b..f3e2d1a81e34aeddebb7644f1ab2af75dc405da4 100644 (file)
@@ -255,7 +255,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 418cead8df9adfca7d10b9c10620b32ee05a472c..678671159b6f0437d8845ee58243bb4ab768daa6 100644 (file)
@@ -116,7 +116,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 d6facc02958f314afa2bf0bcc25e26fc317638a7..9099d85c7a9b5e6f732d7c4bda52332e3ab694fd 100644 (file)
@@ -145,7 +145,7 @@ bool HarvestTimestamp(struct msghdr* msgh, struct timeval* tv)
 }
 bool HarvestDestinationAddress(const struct msghdr* msgh, ComboAddress* destination)
 {
-  memset(destination, 0, sizeof(*destination));
+  destination->reset();
   const struct cmsghdr* cmsg;
   for (cmsg = CMSG_FIRSTHDR(msgh); cmsg != NULL; cmsg = CMSG_NXTHDR(const_cast<struct msghdr*>(msgh), const_cast<struct cmsghdr*>(cmsg))) {
 #if defined(IP_PKTINFO)
index 8ab4f13c3473311d8e82625e461e26eabc95165e..40829bbbd98775ad37a064190c644f9bd6f95ed7 100644 (file)
@@ -282,6 +282,12 @@ union ComboAddress {
     return ntohs(sin4.sin_port);
   }
 
+  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 b32eff9bfee5a3a03aa1dbb4740cf3480ee2c0ed..5f4b991f3254588f62b0629af3a935296deecb6c 100644 (file)
@@ -720,7 +720,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 a37720ccb174b39de3180735dfa1cdedd3fc4546..0222cd17fdec7e76f6b9d1d4c84608f337763b65 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 4cfb5bd57334606c86c7629fe6f5a4a3b8f016f6..f8f3a948b2900eb10e75caaf78dbd9449a8398db 100644 (file)
@@ -1480,7 +1480,7 @@ static void handleRunningTCPQuestion(int fd, FDMultiplexer::funcparam_t& var)
       dc->d_tcp=true;
       dc->setRemote(&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
@@ -1876,7 +1876,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
@@ -1935,7 +1935,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;
@@ -2021,7 +2021,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 7e2c22bf1dd482350d6298393dc2106edbbc65fe..3a36e12d5eb330dc9f91d4f5bbbfa51cbfe9d612 100644 (file)
@@ -821,7 +821,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 9e620de33c3054a00a16793e3b58754db27bc815..cb9899ac5b31bf0606aa9ece43e8d0a21d79aa3d 100644 (file)
@@ -60,8 +60,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));
 }