From: Remi Gacogne Date: Fri, 29 Jan 2021 16:01:18 +0000 (+0100) Subject: Work around false positives from cppcheck X-Git-Tag: dnsdist-1.6.0-alpha1~1^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=753240f17ba186c38ac35d978d59597377ce64d0;p=thirdparty%2Fpdns.git Work around false positives from cppcheck --- diff --git a/pdns/dnsdistdist/dnsdist-lbpolicies.cc b/pdns/dnsdistdist/dnsdist-lbpolicies.cc index 882cbfb2a1..d01ccd69ac 100644 --- a/pdns/dnsdistdist/dnsdist-lbpolicies.cc +++ b/pdns/dnsdistdist/dnsdist-lbpolicies.cc @@ -106,7 +106,7 @@ static shared_ptr 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(); } diff --git a/pdns/dnsdistdist/dnsdist-lua-ffi.cc b/pdns/dnsdistdist/dnsdist-lua-ffi.cc index 602aafa466..a90a952ebc 100644 --- a/pdns/dnsdistdist/dnsdist-lua-ffi.cc +++ b/pdns/dnsdistdist/dnsdist-lua-ffi.cc @@ -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; diff --git a/pdns/dnsdistdist/dnsdist-tcp-downstream.cc b/pdns/dnsdistdist/dnsdist-tcp-downstream.cc index 19a0563c90..a66469f3ff 100644 --- a/pdns/dnsdistdist/dnsdist-tcp-downstream.cc +++ b/pdns/dnsdistdist/dnsdist-tcp-downstream.cc @@ -552,14 +552,18 @@ void TCPConnectionToBackend::setProxyProtocolValuesSent(std::unique_ptr>& 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; } diff --git a/pdns/iputils.hh b/pdns/iputils.hh index 6b36d1e19d..3fd37a83d1 100644 --- a/pdns/iputils.hh +++ b/pdns/iputils.hh @@ -353,7 +353,7 @@ union ComboAddress { uint32_t ls_addr = ntohl(sin4.sin_addr.s_addr); - return ((ls_addr & (1<= 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 new_child2(new_node); + unique_ptr new_child2 = make_unique(key); + TreeNode* new_node = new_child2.get(); // attach the new child nodes below the branch node // (left or right depending on bit)