]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Work around false positives from cppcheck
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 29 Jan 2021 16:01:18 +0000 (17:01 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 29 Jan 2021 16:01:18 +0000 (17:01 +0100)
pdns/dnsdistdist/dnsdist-lbpolicies.cc
pdns/dnsdistdist/dnsdist-lua-ffi.cc
pdns/dnsdistdist/dnsdist-tcp-downstream.cc
pdns/iputils.hh

index 882cbfb2a1e4c78436b83247af91e1efaf7ee16d..d01ccd69acaceb0eb5a585a8cad8894a42d7b80e 100644 (file)
@@ -106,7 +106,7 @@ static shared_ptr<DownstreamState> valrandom(unsigned int val, const ServerPolic
   }
 
   // Catch poss & sum are empty to avoid SIGFPE
-  if (poss.empty()) {
+  if (poss.empty() || sum == 0) {
     return shared_ptr<DownstreamState>();
   }
 
index 602aafa466fd655937546cdac6e80e375c0e8a30..a90a952ebc2b22ee870fb0c7af8e9f988f0a3ef5 100644 (file)
@@ -267,6 +267,10 @@ size_t dnsdist_ffi_dnsquestion_get_edns_options(dnsdist_ffi_dnsquestion_t* dq, c
 {
   if (dq->dq->ednsOptions == nullptr) {
     parseEDNSOptions(*(dq->dq));
+
+    if (dq->dq->ednsOptions == nullptr) {
+      return 0;
+    }
   }
 
   size_t totalCount = 0;
index 19a0563c90cbc13e2c403be5ceb2480fa1333ec4..a66469f3ffd8cf31ccbce45c503c7870e20e3493 100644 (file)
@@ -552,14 +552,18 @@ void TCPConnectionToBackend::setProxyProtocolValuesSent(std::unique_ptr<std::vec
 
 bool TCPConnectionToBackend::matchesTLVs(const std::unique_ptr<std::vector<ProxyProtocolValue>>& tlvs) const
 {
-  if (tlvs == nullptr && d_proxyProtocolValuesSent == nullptr) {
-    return true;
-  }
-  if (tlvs == nullptr && d_proxyProtocolValuesSent != nullptr) {
-    return false;
+  if (tlvs == nullptr) {
+    if (d_proxyProtocolValuesSent == nullptr) {
+      return true;
+    }
+    else {
+      return false;
+    }
   }
-  if (tlvs != nullptr && d_proxyProtocolValuesSent == nullptr) {
+
+  if (d_proxyProtocolValuesSent == nullptr) {
     return false;
   }
+
   return *tlvs == *d_proxyProtocolValuesSent;
 }
index 6b36d1e19d1093bf3131d0c421d9ed9cf9ce0617..3fd37a83d1ce4659eb4c4981904662561247c461 100644 (file)
@@ -353,7 +353,7 @@ union ComboAddress {
 
       uint32_t ls_addr = ntohl(sin4.sin_addr.s_addr);
 
-      return ((ls_addr & (1<<index)) != 0x00000000);
+      return ((ls_addr & (1U<<index)) != 0x00000000);
     }
     if(isIPv6()) {
       if (index >= 128)
@@ -368,7 +368,7 @@ union ComboAddress {
       uint8_t byte_idx = index / 8;
       uint8_t bit_idx = index % 8;
 
-      return ((ls_addr[15-byte_idx] & (1 << bit_idx)) != 0x00);
+      return ((ls_addr[15-byte_idx] & (1U << bit_idx)) != 0x00);
     }
     return false;
   }
@@ -781,8 +781,8 @@ private:
       branch_node->parent = parent;
 
       // create second new leaf node for the new key
-      TreeNode* new_node = new TreeNode(key);
-      unique_ptr<TreeNode> new_child2(new_node);
+      unique_ptr<TreeNode> new_child2 = make_unique<TreeNode>(key);
+      TreeNode* new_node = new_child2.get();
 
       // attach the new child nodes below the branch node
       // (left or right depending on bit)