]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Fix compiler/static analyzer warnings 10993/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 16 Nov 2021 16:36:03 +0000 (17:36 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 16 Nov 2021 16:36:03 +0000 (17:36 +0100)
pdns/bpf-filter.cc
pdns/dnsdistdist/dnsdist-tcp-downstream.cc
pdns/remote_logger.cc

index 29bd6fe313491b3e476591b994dfbad98d2bd1cf..d0ec0f617225f58cae9989bb2354fc18470fcf7f 100644 (file)
@@ -35,19 +35,8 @@ static __u64 ptr_to_u64(void *ptr)
   return (__u64) (unsigned long) ptr;
 }
 
-int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size,
-                   int max_entries)
-{
-  union bpf_attr attr;
-  memset(&attr, 0, sizeof(attr));
-  attr.map_type = map_type;
-  attr.key_size = key_size;
-  attr.value_size = value_size;
-  attr.max_entries = max_entries;
-  return syscall(SYS_bpf, BPF_MAP_CREATE, &attr, sizeof(attr));
-}
-
-int bpf_pin_map(int fd, const std::string& path)
+/* these can be static as they are not declared in libbpf.h: */
+static int bpf_pin_map(int fd, const std::string& path)
 {
   union bpf_attr attr;
   memset(&attr, 0, sizeof(attr));
@@ -56,7 +45,7 @@ int bpf_pin_map(int fd, const std::string& path)
   return syscall(SYS_bpf, BPF_OBJ_PIN, &attr, sizeof(attr));
 }
 
-int bpf_load_pinned_map(const std::string& path)
+static int bpf_load_pinned_map(const std::string& path)
 {
   union bpf_attr attr;
   memset(&attr, 0, sizeof(attr));
@@ -64,7 +53,7 @@ int bpf_load_pinned_map(const std::string& path)
   return syscall(SYS_bpf, BPF_OBJ_GET, &attr, sizeof(attr));
 }
 
-void bpf_check_map_sizes(int fd, uint32_t expectedKeySize, uint32_t expectedValueSize)
+static void bpf_check_map_sizes(int fd, uint32_t expectedKeySize, uint32_t expectedValueSize)
 {
   struct bpf_map_info info;
   uint32_t info_len = sizeof(info);
@@ -91,6 +80,18 @@ void bpf_check_map_sizes(int fd, uint32_t expectedKeySize, uint32_t expectedValu
   }
 }
 
+int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size,
+                   int max_entries)
+{
+  union bpf_attr attr;
+  memset(&attr, 0, sizeof(attr));
+  attr.map_type = map_type;
+  attr.key_size = key_size;
+  attr.value_size = value_size;
+  attr.max_entries = max_entries;
+  return syscall(SYS_bpf, BPF_MAP_CREATE, &attr, sizeof(attr));
+}
+
 int bpf_update_elem(int fd, void *key, void *value, unsigned long long flags)
 {
   union bpf_attr attr;
@@ -475,13 +476,11 @@ void BPFFilter::block(const DNSName& qname, BPFFilter::MatchAction action, uint1
   void* value = nullptr;
 
   if (d_external) {
-    memset(&cadvalue, 0, sizeof(cadvalue));
     cadvalue.counter = 0;
     cadvalue.action = action;
     value = &cadvalue;
   }
   else {
-    memset(&qvalue, 0, sizeof(qvalue));
     qvalue.counter = 0;
     qvalue.qtype = qtype;
     value = &qvalue;
index 7d3158cc215d7db267f1c187e992abc6893c593f..9c636d227c177b16a640142eb63592d9ce6af38d 100644 (file)
@@ -515,7 +515,9 @@ void TCPConnectionToBackend::notifyAllQueriesFailed(const struct timeval& now, F
   /* we might be terminated while notifying a query sender */
   d_ds->outstanding -= d_pendingResponses.size();
   auto pendingQueries = std::move(d_pendingQueries);
+  d_pendingQueries.clear();
   auto pendingResponses = std::move(d_pendingResponses);
+  d_pendingResponses.clear();
 
   auto increaseCounters = [reason](std::shared_ptr<TCPQuerySender>& sender) {
     if (reason == FailureReason::timeout) {
index 6e41db647f4e843b44227c84115334295b043031..96e596888c814991cd8f039160887a36fe8454df 100644 (file)
@@ -47,12 +47,10 @@ bool CircularWriteBuffer::flush(int fd)
 
   struct iovec iov[2];
   int pos = 0;
-  size_t total = 0;
   for(const auto& arr : {arr1, arr2}) {
     if(arr.second) {
       iov[pos].iov_base = arr.first;
       iov[pos].iov_len = arr.second;
-      total += arr.second;
       ++pos;
     }
   }
@@ -84,7 +82,6 @@ bool CircularWriteBuffer::flush(int fd)
   }
   while (res < 0);
 
-  //  cout<<"Flushed "<<res<<" bytes out of " << total <<endl;
   if (static_cast<size_t>(res) == d_buffer.size()) {
     d_buffer.clear();
   }