aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/usrp_clock/octoclock/octoclock_uart.cpp
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2020-01-23 11:02:15 -0800
committeratrnati <54334261+atrnati@users.noreply.github.com>2020-02-04 08:53:01 -0600
commit4b1d346a80f860ebcf26712b721606c19dd904dd (patch)
tree31ee6a6a42ffdf3623b8695cfa17cec5f8adebf8 /host/lib/usrp_clock/octoclock/octoclock_uart.cpp
parent22db12c4b2b55225801ec1efb2465c7a06295b9e (diff)
downloaduhd-4b1d346a80f860ebcf26712b721606c19dd904dd.tar.gz
uhd-4b1d346a80f860ebcf26712b721606c19dd904dd.tar.bz2
uhd-4b1d346a80f860ebcf26712b721606c19dd904dd.zip
octoclock: Avoid usage of uninitialized memory
The Octoclock host code would send uninitialized memory over the network, which would be flagged by tools such as Valgrind. This patch creates a factory function for OctoClock packets that initializes the memory to zero, defaults the proto version to the OctoClock default, and can provide a random sequence number if none is given.
Diffstat (limited to 'host/lib/usrp_clock/octoclock/octoclock_uart.cpp')
-rw-r--r--host/lib/usrp_clock/octoclock/octoclock_uart.cpp13
1 files changed, 5 insertions, 8 deletions
diff --git a/host/lib/usrp_clock/octoclock/octoclock_uart.cpp b/host/lib/usrp_clock/octoclock/octoclock_uart.cpp
index 15c503888..4f4ad1e55 100644
--- a/host/lib/usrp_clock/octoclock/octoclock_uart.cpp
+++ b/host/lib/usrp_clock/octoclock/octoclock_uart.cpp
@@ -7,6 +7,7 @@
#include "octoclock_uart.hpp"
#include "common.h"
+#include "octoclock_impl.hpp"
#include <uhd/exception.hpp>
#include <uhd/utils/byteswap.hpp>
#include <stdint.h>
@@ -42,9 +43,7 @@ octoclock_uart_iface::octoclock_uart_iface(udp_simple::sptr udp, uint32_t proto_
size_t len = 0;
// Get pool size from device
- octoclock_packet_t pkt_out;
- pkt_out.sequence = uhd::htonx<uint32_t>(_sequence);
- pkt_out.len = 0;
+ auto pkt_out = make_octoclock_packet(uhd::htonx<uint32_t>(_sequence));
uint8_t octoclock_data[udp_simple::mtu];
const octoclock_packet_t* pkt_in =
@@ -63,9 +62,8 @@ void octoclock_uart_iface::write_uart(const std::string& buf)
{
size_t len = 0;
- octoclock_packet_t pkt_out;
- pkt_out.sequence = uhd::htonx<uint32_t>(++_sequence);
- pkt_out.len = buf.size();
+ auto pkt_out = make_octoclock_packet(uhd::htonx<uint32_t>(++_sequence));
+ pkt_out.len = buf.size();
memcpy(pkt_out.data, buf.c_str(), buf.size());
uint8_t octoclock_data[udp_simple::mtu];
@@ -108,8 +106,7 @@ std::string octoclock_uart_iface::read_uart(double timeout)
void octoclock_uart_iface::_update_cache()
{
- octoclock_packet_t pkt_out;
- pkt_out.len = 0;
+ auto pkt_out = make_octoclock_packet();
size_t len = 0;
uint8_t octoclock_data[udp_simple::mtu];