]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Hopefully appease the static analyzer gods 14255/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 28 May 2024 08:31:02 +0000 (10:31 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 28 May 2024 08:31:02 +0000 (10:31 +0200)
pdns/dnsdistdist/dnsdist-lua-ffi.cc
pdns/dnsdistdist/test-dnsdist-lua-ffi.cc

index 48d6bb5a5c3c3ee780aec852e67d2bc027ed14e3..e399c438c5dd576272a05eb9942755fe83a0b22a 100644 (file)
@@ -1092,11 +1092,11 @@ bool dnsdist_ffi_dnsquestion_add_proxy_protocol_values(dnsdist_ffi_dnsquestion_t
   if (!dnsQuestion->dq->proxyProtocolValues) {
     dnsQuestion->dq->proxyProtocolValues = make_unique<std::vector<ProxyProtocolValue>>();
   }
-  if (valuesCount > 0) {
-    dnsQuestion->dq->proxyProtocolValues->reserve(dnsQuestion->dq->proxyProtocolValues->size() + valuesCount);
-    for (size_t idx = 0; idx < valuesCount; idx++) {
-      dnsQuestion->dq->proxyProtocolValues->push_back({ std::string(values[idx].value, values[idx].size), values[idx].type });
-    }
+
+  dnsQuestion->dq->proxyProtocolValues->reserve(dnsQuestion->dq->proxyProtocolValues->size() + valuesCount);
+  for (size_t idx = 0; idx < valuesCount; idx++) {
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic): the Lua FFI API is a C API..
+    dnsQuestion->dq->proxyProtocolValues->push_back({ std::string(values[idx].value, values[idx].size), values[idx].type });
   }
 
   return true;
index c58a205bfbb56c57d1faeb309d9f2ae8535fdce2..d0cd68ea5563bdf71c2a29f25f1e99dda38153f9 100644 (file)
@@ -590,8 +590,8 @@ BOOST_AUTO_TEST_CASE(test_ProxyProtocolQuery)
   pwQ.getHeader()->rd = 1;
   pwQ.getHeader()->id = htons(42);
 
-  DNSQuestion dq(ids, query);
-  dnsdist_ffi_dnsquestion_t lightDQ(&dq);
+  DNSQuestion dnsQuestion(ids, query);
+  dnsdist_ffi_dnsquestion_t lightDQ(&dnsQuestion);
 
   std::vector<dnsdist_ffi_proxy_protocol_value> values;
   values.push_back({"test-value", 10U, 1U});
@@ -614,11 +614,11 @@ BOOST_AUTO_TEST_CASE(test_ProxyProtocolQuery)
   {
     auto added = dnsdist_ffi_dnsquestion_add_proxy_protocol_values(&lightDQ, values.size(), values.data());
     BOOST_CHECK_EQUAL(added, true);
-    BOOST_REQUIRE(dq.proxyProtocolValues != nullptr);
-    BOOST_REQUIRE_EQUAL(dq.proxyProtocolValues->size(), values.size());
-    BOOST_CHECK_EQUAL(dq.proxyProtocolValues->at(0).type, values.at(0).type);
-    BOOST_REQUIRE_EQUAL(dq.proxyProtocolValues->at(0).content.size(), values.at(0).size);
-    BOOST_CHECK_EQUAL(memcmp(dq.proxyProtocolValues->at(0).content.data(), values.at(0).value, values.at(0).size), 0);
+    BOOST_REQUIRE(dnsQuestion.proxyProtocolValues != nullptr);
+    BOOST_REQUIRE_EQUAL(dnsQuestion.proxyProtocolValues->size(), values.size());
+    BOOST_CHECK_EQUAL(dnsQuestion.proxyProtocolValues->at(0).type, values.at(0).type);
+    BOOST_REQUIRE_EQUAL(dnsQuestion.proxyProtocolValues->at(0).content.size(), values.at(0).size);
+    BOOST_CHECK_EQUAL(memcmp(dnsQuestion.proxyProtocolValues->at(0).content.data(), values.at(0).value, values.at(0).size), 0);
   }
 }