From 7b966fe4a6b266c9f4da3f4ed50a7fd79414cb7d Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Fri, 16 Sep 2022 15:38:54 -0500 Subject: [PATCH] Fixed incorrect handling of partial frame tagged onto the end of a complete frame. Not sure if my method drops the partial or just sends the buffer back to continue filling. --- connections/socketcand.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/connections/socketcand.cpp b/connections/socketcand.cpp index 9bbddbb..cfac211 100644 --- a/connections/socketcand.cpp +++ b/connections/socketcand.cpp @@ -263,6 +263,12 @@ void SocketCANd::decodeFrames(QString data, int busNum) QString frameStr = frameStrConst; QStringList frameParsed = (frameStr.remove(QRegExp("^<")).remove(QRegExp(">$"))).simplified().split(' '); + if(frameParsed.length() < 2) + { + qDebug() << "Received datagramm is an incomplete frame: " << data; + return; + } + buildFrame.setFrameId(frameParsed[1].toUInt(nullptr, 16)); buildFrame.bus = busNum; @@ -271,6 +277,13 @@ void SocketCANd::decodeFrames(QString data, int busNum) buildFrame.setTimeStamp(QCanBusFrame::TimeStamp(0, frameParsed[2].toDouble() * 1000000l)); //buildFrame.len = frameParsed[3].length() * 0.5; + + if(frameParsed.length() < 4) + { + qDebug() << "Received frame doesn't contain any data: " << data; + return; + } + int framelength = frameParsed[3].length() * 0.5; buildData.resize(framelength);