From d0ccc0ee6105a3956cf04004e31389953488961b Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sun, 14 Mar 2021 16:24:48 +0000 Subject: [PATCH] Try and fix a crash. --- FMControl.cpp | 2 +- FMNetwork.cpp | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/FMControl.cpp b/FMControl.cpp index c44c324..7f1ff07 100644 --- a/FMControl.cpp +++ b/FMControl.cpp @@ -147,7 +147,7 @@ unsigned int CFMControl::readModem(unsigned char* data, unsigned int space) space = 240U; // 160 samples 12-bit float netData[160U]; // Modem can handle up to 160 samples at a time - unsigned int length = m_network->read(netData, 160U); //160 samples 12-bit + unsigned int length = m_network->read(netData, 160U); // 160 samples 12-bit if (length == 0U) return 0U; diff --git a/FMNetwork.cpp b/FMNetwork.cpp index 85947c9..947ceb8 100644 --- a/FMNetwork.cpp +++ b/FMNetwork.cpp @@ -25,7 +25,7 @@ #include #include -const unsigned int BUFFER_LENGTH = 500U; +const unsigned int BUFFER_LENGTH = 1500U; CFMNetwork::CFMNetwork(const std::string& protocol, const std::string& localAddress, unsigned int localPort, const std::string& gatewayAddress, unsigned int gatewayPort, unsigned int sampleRate, bool debug) : m_protocol(FMNP_MMDVM), @@ -111,8 +111,8 @@ bool CFMNetwork::writeData(float* data, unsigned int nSamples) } #endif - unsigned char buffer[2000U]; - ::memset(buffer, 0x00U, 2000U); + unsigned char buffer[1500U]; + ::memset(buffer, 0x00U, 1500U); unsigned int length = 0U; @@ -237,6 +237,9 @@ void CFMNetwork::clock(unsigned int ms) if (::memcmp(buffer, "USRP", 4U) != 0) return; + if (length < 32) + return; + // The type is a big-endian 4-byte integer unsigned int type = (buffer[20U] << 24) + (buffer[21U] << 16) + @@ -254,6 +257,9 @@ void CFMNetwork::clock(unsigned int ms) if (::memcmp(buffer, "FMD", 3U) != 0) return; + if (length < 3) + return; + m_buffer.addData(buffer + 3U, length - 3U); } }