summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-09-29 18:12:32 +0200
committerSven Gothel <[email protected]>2020-09-29 18:12:32 +0200
commit1954e10d7a4cdfbafb93230ea12dac1cf49ff57a (patch)
tree4ebf3dcb5afe0fda9e185ae29cf2e5e433aff358 /src
parent9a0964148e93e14005c8f5425af794b736cdd10d (diff)
valgrind memcheck: Avoid warnings on ::bind(..), use whole struct sockaddr as memory region holding sockaddr_hci
Diffstat (limited to 'src')
-rw-r--r--src/direct_bt/HCIComm.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/direct_bt/HCIComm.cpp b/src/direct_bt/HCIComm.cpp
index ffcfc97c..19dcfaaf 100644
--- a/src/direct_bt/HCIComm.cpp
+++ b/src/direct_bt/HCIComm.cpp
@@ -31,6 +31,7 @@
#include <cstdio>
#include <algorithm>
+#include <type_traits>
// #define PERF_PRINT_ON 1
#include <dbt_debug.hpp>
@@ -52,7 +53,9 @@ namespace direct_bt {
int HCIComm::hci_open_dev(const uint16_t dev_id, const uint16_t channel) noexcept
{
- sockaddr_hci a;
+ static_assert( sizeof(struct sockaddr) > sizeof(sockaddr_hci), "Requirement sizeof(struct sockaddr) > sizeof(sockaddr_hci)" );
+ sockaddr addr_holder; // sizeof(struct sockaddr) > sizeof(sockaddr_hci), silent valgrind.
+ sockaddr_hci * ptr_hci_addr = (sockaddr_hci*)&addr_holder;
int fd, err;
/**
@@ -71,11 +74,11 @@ int HCIComm::hci_open_dev(const uint16_t dev_id, const uint16_t channel) noexcep
}
// Bind socket to the HCI device
- bzero((void *)&a, sizeof(a));
- a.hci_family = AF_BLUETOOTH;
- a.hci_dev = dev_id;
- a.hci_channel = channel;
- if (bind(fd, (struct sockaddr *) &a, sizeof(a)) < 0) {
+ bzero(&addr_holder, sizeof(addr_holder));
+ ptr_hci_addr->hci_family = AF_BLUETOOTH;
+ ptr_hci_addr->hci_dev = dev_id;
+ ptr_hci_addr->hci_channel = channel;
+ if (bind(fd, &addr_holder, sizeof(sockaddr_hci)) < 0) {
ERR_PRINT("hci_open_dev: bind failed");
goto failed;
}