From 4b1d346a80f860ebcf26712b721606c19dd904dd Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Thu, 23 Jan 2020 11:02:15 -0800 Subject: 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. --- host/lib/usrp_clock/octoclock/octoclock_uart.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'host/lib/usrp_clock/octoclock/octoclock_uart.cpp') 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 #include #include @@ -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(_sequence); - pkt_out.len = 0; + auto pkt_out = make_octoclock_packet(uhd::htonx(_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(++_sequence); - pkt_out.len = buf.size(); + auto pkt_out = make_octoclock_packet(uhd::htonx(++_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]; -- cgit v1.2.3