From 78b34afc9acb0be84e6596f452cd2c907e2af1b2 Mon Sep 17 00:00:00 2001 From: Alexey Esaulenko Date: Thu, 18 Jan 2024 11:00:15 +0400 Subject: [PATCH 01/10] Minor: fix Frame Info window layout (same Widget names produced warning during compilation) --- ui/frameinfowindow.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/frameinfowindow.ui b/ui/frameinfowindow.ui index 0b613946..375c63e7 100644 --- a/ui/frameinfowindow.ui +++ b/ui/frameinfowindow.ui @@ -120,7 +120,7 @@ - + From 578894600a75a0592285523bd7f76dbf9c0cf2ac Mon Sep 17 00:00:00 2001 From: Alexey Esaulenko Date: Thu, 18 Jan 2024 11:29:47 +0400 Subject: [PATCH 02/10] Access to the CANBus parameters only through setters/getters Also removed explicit copy constructor, in such trivial cases compiler can create all needed copy/move stubs automatically --- connections/canbus.cpp | 27 +++++++++-------------- connections/canbus.h | 33 +++++++++++++++-------------- connections/serialbusconnection.cpp | 15 ++++++------- 3 files changed, 34 insertions(+), 41 deletions(-) diff --git a/connections/canbus.cpp b/connections/canbus.cpp index 3779e86e..0623baa8 100644 --- a/connections/canbus.cpp +++ b/connections/canbus.cpp @@ -13,21 +13,13 @@ CANBus::CANBus() } -CANBus::CANBus(const CANBus& pBus) : - speed(pBus.speed), - listenOnly(pBus.listenOnly), - singleWire(pBus.singleWire), - active(pBus.active), - canFD(pBus.canFD), - dataRate(pBus.dataRate){} - - bool CANBus::operator==(const CANBus& bus) const{ return speed == bus.speed && listenOnly == bus.listenOnly && singleWire == bus.singleWire && active == bus.active && - canFD == bus.canFD; + canFD == bus.canFD && + dataRate == bus.dataRate; } void CANBus::setSpeed(int newSpeed){ @@ -55,11 +47,11 @@ void CANBus::setCanFD(bool mode){ canFD = mode; } -int CANBus::getSpeed(){ +int CANBus::getSpeed() const { return speed; } -int CANBus::getDataRate(){ +int CANBus::getDataRate() const { return dataRate; } @@ -68,29 +60,30 @@ void CANBus::setDataRate(int newSpeed){ dataRate = newSpeed; } -bool CANBus::isListenOnly(){ +bool CANBus::isListenOnly() const { return listenOnly; } -bool CANBus::isSingleWire(){ +bool CANBus::isSingleWire() const { return singleWire; } -bool CANBus::isActive(){ +bool CANBus::isActive() const { return active; } -bool CANBus::isCanFD(){ +bool CANBus::isCanFD() const { return canFD; } -QDataStream& operator<<( QDataStream & pStream, const CANBus& pCanBus ) +QDataStream& operator<<(QDataStream & pStream, const CANBus& pCanBus) { pStream << pCanBus.speed; pStream << pCanBus.listenOnly; pStream << pCanBus.singleWire; pStream << pCanBus.active; + // FIXME CANFD settings missing return pStream; } diff --git a/connections/canbus.h b/connections/canbus.h index ff3d8878..61fc122b 100644 --- a/connections/canbus.h +++ b/connections/canbus.h @@ -5,13 +5,6 @@ class CANBus { -public: - CANBus(); - CANBus(const CANBus&); - bool operator==(const CANBus&) const; - CANBus& operator=(const CANBus& other) = default; - //virtual ~CANBus(){} - int speed; bool listenOnly; bool singleWire; @@ -19,28 +12,36 @@ class CANBus bool canFD; int dataRate; + friend QDataStream& operator<<(QDataStream & pStream, const CANBus& pCanBus); + friend QDataStream& operator>>(QDataStream & pStream, CANBus& pCanBus); +public: + CANBus(); + + bool operator==(const CANBus&) const; + void setSpeed(int); // new speed void setListenOnly(bool); //bool for whether to only listen void setSingleWire(bool); //bool for whether to use single wire mode void setActive(bool); //whether this bus should be enabled or not. void setCanFD(bool); // enable or disable CANFD support - int getSpeed(); - int getDataRate(); void setDataRate(int newSpeed); - bool isListenOnly(); - bool isSingleWire(); - bool isActive(); - bool isCanFD(); + + int getSpeed() const; + int getDataRate() const; + bool isListenOnly() const; + bool isSingleWire() const; + bool isActive() const; + bool isCanFD() const; }; -QDataStream& operator<<( QDataStream & pStream, const CANBus& pCanBus ); -QDataStream & operator>>(QDataStream & pStream, CANBus& pCanBus); +QDataStream& operator<<(QDataStream & pStream, const CANBus& pCanBus); +QDataStream& operator>>(QDataStream & pStream, CANBus& pCanBus); Q_DECLARE_METATYPE(CANBus); struct BusData { CANBus mBus; - bool mConfigured; + bool mConfigured = {}; QVector mTargettedFrames; }; diff --git a/connections/serialbusconnection.cpp b/connections/serialbusconnection.cpp index a5ec860e..8ebebbfc 100644 --- a/connections/serialbusconnection.cpp +++ b/connections/serialbusconnection.cpp @@ -94,7 +94,7 @@ void SerialBusConnection::piSetBusSettings(int pBusIdx, CANBus bus) setBusConfig(0, bus); /* if bus is not active we are done */ - if(!bus.active) + if(!bus.isActive()) return; /* set configuration */ @@ -105,10 +105,10 @@ void SerialBusConnection::piSetBusSettings(int pBusIdx, CANBus bus) //You cannot set the speed of a socketcan interface, it has to be set with console commands. //But, you can probabaly set the speed of many of the other serialbus devices so go ahead and try - mDev_p->setConfigurationParameter(QCanBusDevice::BitRateKey, bus.speed); - mDev_p->setConfigurationParameter(QCanBusDevice::CanFdKey, bus.canFD); + mDev_p->setConfigurationParameter(QCanBusDevice::BitRateKey, bus.getSpeed()); + mDev_p->setConfigurationParameter(QCanBusDevice::CanFdKey, bus.isCanFD()); - if(bus.listenOnly) + if(bus.isListenOnly()) sbusconfig |= EN_SILENT_MODE; mDev_p->setConfigurationParameter(QCanBusDevice::UserKey, sbusconfig); @@ -188,6 +188,7 @@ void SerialBusConnection::framesReceived() /* check frame */ //if (recFrame.payload().length() <= 8) { + if (true) { CANFrame* frame_p = getQueue().get(); if(frame_p) { frame_p->setPayload(recFrame.payload()); @@ -206,7 +207,7 @@ void SerialBusConnection::framesReceived() frame_p->setTimeStamp(recFrame.timeStamp()); frame_p->setFrameType(recFrame.frameType()); frame_p->setError(recFrame.error()); - /* If recorded frame has a local echo, it is a Tx message, and thus should not be marked as Rx */ + /* If recorded frame has a local echo, it is a Tx message, and thus should not be marked as Rx */ frame_p->isReceived = !recFrame.hasLocalEcho(); if (useSystemTime) { @@ -218,11 +219,9 @@ void SerialBusConnection::framesReceived() /* enqueue frame */ getQueue().queue(); - //} -#if 0 + } else qDebug() << "can't get a frame, ERROR"; -#endif } } } From fbfe55c90505064e5c53e0381863ad6686da3086 Mon Sep 17 00:00:00 2001 From: Alexey Esaulenko Date: Thu, 18 Jan 2024 11:52:22 +0400 Subject: [PATCH 03/10] GraphingWindow: don't use size_t as indexes for Qt containers --- re/graphingwindow.cpp | 46 ++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/re/graphingwindow.cpp b/re/graphingwindow.cpp index f2a41e76..860aa7f4 100644 --- a/re/graphingwindow.cpp +++ b/re/graphingwindow.cpp @@ -779,12 +779,12 @@ void GraphingWindow::saveSpreadsheet() QList::iterator iter; double xMin = std::numeric_limits::max(), xMax = std::numeric_limits::min(); - size_t maxCount = 0; - size_t numGraphs = graphParams.length(); + int maxCount = 0; + int numGraphs = graphParams.length(); for (auto && graph : graphParams) { xMin = std::min(xMin, graph.x[0]); xMax = std::max(xMax, graph.x[graph.x.count() - 1]); - maxCount = std::max(maxCount, static_cast(graph.x.count())); + maxCount = std::max(maxCount, graph.x.count()); } qDebug() << "xMin: " << xMin; qDebug() << "xMax: " << xMax; @@ -795,8 +795,6 @@ void GraphingWindow::saveSpreadsheet() double xSize = xMax - xMin; double sliceSize = xSize / ((double)maxCount); double equivValue = sliceSize / 100.0; - double currentX; - double value; QList indices; indices.reserve(numGraphs); @@ -808,14 +806,14 @@ void GraphingWindow::saveSpreadsheet() } outFile->write("\n"); - for (size_t j = 1; j < (maxCount - 1); j++) + for (int j = 1; j < (maxCount - 1); j++) { - currentX = xMin + (j * sliceSize); + double currentX = xMin + (j * sliceSize); qDebug() << "X: " << currentX; outFile->write(QString::number(currentX, 'f').toUtf8()); - for (size_t k = 0; k < numGraphs; k++) + for (int k = 0; k < numGraphs; k++) { - value = 0.0; + double value = 0.0; // move cursor to last sample before currentX while (graphParams[k].x[indices[k]+1] < currentX) @@ -849,7 +847,7 @@ void GraphingWindow::saveSpreadsheet() else { // find index, where x >= currentX - size_t cursor = indices[k]; + int cursor = indices[k]; double span = graphParams[k].x[cursor+1] - graphParams[k].x[cursor]; double progress = (currentX - graphParams[k].x[cursor]) / span; Q_ASSERT(progress >= 0.0 && progress <= 1.0); @@ -1325,10 +1323,8 @@ void GraphingWindow::createGraph(GraphParams ¶ms, bool createGraphParam) double yminval=10000000.0, ymaxval = -1000000.0; double xminval=10000000000.0, xmaxval = -10000000000.0; GraphParams *refParam = ¶ms; - int sBit, bits; - bool intelFormat, isSigned; QString tempStr; - double x,y; + double x{}, y{}; qDebug() << "New Graph ID: " << params.ID; qDebug() << "Start bit: " << params.startBit; @@ -1365,10 +1361,10 @@ void GraphingWindow::createGraph(GraphParams ¶ms, bool createGraphParam) //params.x.fill(0, numEntries); //params.y.fill(0, numEntries); - sBit = params.startBit; - bits = params.numBits; - intelFormat = params.intelFormat; - isSigned = params.isSigned; + int sBit = params.startBit; + int bits = params.numBits; + bool intelFormat = params.intelFormat; + bool isSigned = params.isSigned; for (int j = 0; j < numEntries; j++) { @@ -1558,16 +1554,16 @@ void GraphingWindow::createGraph(GraphParams ¶ms, bool createGraphParam) void GraphingWindow::moveLegend() { qDebug() << "moveLegend"; - if (QAction* contextAction = qobject_cast(sender())) // make sure this slot is really called by a context menu action, so it carries the data we need - { - bool ok; - int dataInt = contextAction->data().toInt(&ok); - if (ok) + if (QAction* contextAction = qobject_cast(sender())) // make sure this slot is really called by a context menu action, so it carries the data we need { - ui->graphingView->axisRect()->insetLayout()->setInsetAlignment(0, (Qt::Alignment)dataInt); - ui->graphingView->replot(); + bool ok; + int dataInt = contextAction->data().toInt(&ok); + if (ok) + { + ui->graphingView->axisRect()->insetLayout()->setInsetAlignment(0, (Qt::Alignment)dataInt); + ui->graphingView->replot(); + } } - } } GraphParams::GraphParams() From 97d9f68bb789104f9b15052f3df8e33c0b9e4caf Mon Sep 17 00:00:00 2001 From: Alexey Esaulenko Date: Thu, 18 Jan 2024 12:44:16 +0400 Subject: [PATCH 04/10] CANConnection constructor: use correct order of members in the initialization list --- connections/canconnection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connections/canconnection.cpp b/connections/canconnection.cpp index 74e4fb87..9eac8176 100644 --- a/connections/canconnection.cpp +++ b/connections/canconnection.cpp @@ -13,11 +13,11 @@ CANConnection::CANConnection(QString pPort, int pQueueLen, bool pUseThread) : mNumBuses(pNumBuses), + mSerialSpeed(pSerialSpeed), mQueue(), mPort(pPort), mDriver(pDriver), mType(pType), - mSerialSpeed(pSerialSpeed), mIsCapSuspended(false), mStatus(CANCon::NOT_CONNECTED), mStarted(false), From 3e85c74cfa9473fa576298019cb90a7554654933 Mon Sep 17 00:00:00 2001 From: Alexey Esaulenko Date: Thu, 18 Jan 2024 12:52:25 +0400 Subject: [PATCH 05/10] Minor: Utility::formatTimestamp() suppress compiler warning --- utility.h | 1 + 1 file changed, 1 insertion(+) diff --git a/utility.h b/utility.h index 01abc3da..88bbb318 100644 --- a/utility.h +++ b/utility.h @@ -190,6 +190,7 @@ class Utility return (double)timestamp / 1000000.0; break; } + return QVariant(); // should never happen } //parses the input string to grab as much of it as possible while staying alpha numeric From 0b652b8da1efff3a02412da453ea5912d029514c Mon Sep 17 00:00:00 2001 From: Alexey Esaulenko Date: Thu, 18 Jan 2024 14:35:02 +0400 Subject: [PATCH 06/10] Minor: fix memory leak on GraphingWindow file operations --- re/graphingwindow.cpp | 154 ++++++++++++++++++++---------------------- re/newgraphdialog.cpp | 1 - 2 files changed, 75 insertions(+), 80 deletions(-) diff --git a/re/graphingwindow.cpp b/re/graphingwindow.cpp index 860aa7f4..d2f25812 100644 --- a/re/graphingwindow.cpp +++ b/re/graphingwindow.cpp @@ -39,7 +39,7 @@ GraphingWindow::GraphingWindow(const QVector *frames, QWidget *parent) if (Utility::timeStyle == TS_CLOCK) { - QSharedPointer timeTicker(new QCPAxisTickerTime); + QSharedPointer timeTicker = QSharedPointer::create(); timeTicker->setTimeFormat("%h:%m:%s.%z"); ui->graphingView->xAxis->setTicker(timeTicker); } @@ -571,7 +571,7 @@ void GraphingWindow::removeSelectedGraph() int idx = -1; for (int i = 0; i < graphParams.count(); i++) { - if (graphParams[i].ref == ui->graphingView->selectedGraphs().first()) + if (graphParams[i].ref == ui->graphingView->selectedGraphs().constFirst()) { idx = i; break; @@ -590,7 +590,7 @@ void GraphingWindow::removeSelectedGraph() graphParams.removeAt(idx); - ui->graphingView->removeGraph(ui->graphingView->selectedGraphs().first()); + ui->graphingView->removeGraph(ui->graphingView->selectedGraphs().constFirst()); if (graphParams.count() == 0) needScaleSetup = true; @@ -605,7 +605,7 @@ void GraphingWindow::editSelectedGraph() int idx = -1; for (int i = 0; i < graphParams.count(); i++) { - if (graphParams[i].ref == ui->graphingView->selectedGraphs().first()) + if (graphParams[i].ref == ui->graphingView->selectedGraphs().constFirst()) { idx = i; break; @@ -701,7 +701,6 @@ void GraphingWindow::contextMenuRequest(QPoint pos) void GraphingWindow::saveGraphs() { - QString filename; QFileDialog dialog(this); QSettings settings; @@ -718,7 +717,7 @@ void GraphingWindow::saveGraphs() if (dialog.exec() == QDialog::Accepted) { - filename = dialog.selectedFiles()[0]; + QString filename = dialog.selectedFiles().constFirst(); settings.setValue("Graphing/LoadSaveDirectory", dialog.directory().path()); if (dialog.selectedNameFilter() == filters[0]) @@ -741,7 +740,6 @@ void GraphingWindow::saveGraphs() void GraphingWindow::saveSpreadsheet() { - QString filename; QFileDialog dialog(this); QSettings settings; @@ -756,14 +754,14 @@ void GraphingWindow::saveSpreadsheet() if (dialog.exec() == QDialog::Accepted) { - filename = dialog.selectedFiles()[0]; + QString filename = dialog.selectedFiles().constFirst(); settings.setValue("Graphing/LoadSaveDirectory", dialog.directory().path()); if (!filename.contains('.')) filename += ".csv"; - QFile *outFile = new QFile(filename); + QFile outFile(filename); - if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text)) + if (!outFile.open(QIODevice::WriteOnly | QIODevice::Text)) return; /* @@ -798,19 +796,19 @@ void GraphingWindow::saveSpreadsheet() QList indices; indices.reserve(numGraphs); - outFile->write("TimeStamp"); + outFile.write("TimeStamp"); for (auto && graph : graphParams) { indices.append(0); - outFile->putChar(','); - outFile->write(graph.graphName.toUtf8()); + outFile.putChar(','); + outFile.write(graph.graphName.toUtf8()); } - outFile->write("\n"); + outFile.write("\n"); for (int j = 1; j < (maxCount - 1); j++) { double currentX = xMin + (j * sliceSize); qDebug() << "X: " << currentX; - outFile->write(QString::number(currentX, 'f').toUtf8()); + outFile.write(QString::number(currentX, 'f').toUtf8()); for (int k = 0; k < numGraphs; k++) { double value = 0.0; @@ -854,20 +852,19 @@ void GraphingWindow::saveSpreadsheet() value = Utility::Lerp(graphParams[k].y[cursor], graphParams[k].y[cursor+1], progress); qDebug() << "Span: " << span << " Prog: " << progress << " Value: " << value; } - outFile->putChar(','); - outFile->write(QString::number(value).toUtf8()); + outFile.putChar(','); + outFile.write(QString::number(value).toUtf8()); } - outFile->write("\n"); + outFile.write("\n"); } - outFile->close(); + outFile.close(); } } void GraphingWindow::saveDefinitions() { - QString filename; QFileDialog dialog(this); QSettings settings; @@ -882,79 +879,78 @@ void GraphingWindow::saveDefinitions() if (dialog.exec() == QDialog::Accepted) { - filename = dialog.selectedFiles()[0]; + QString filename = dialog.selectedFiles().constFirst(); settings.setValue("Graphing/LoadSaveDirectory", dialog.directory().path()); if (!filename.contains('.')) filename += ".gdf"; - QFile *outFile = new QFile(filename); + QFile outFile(filename); - if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text)) + if (!outFile.open(QIODevice::WriteOnly | QIODevice::Text)) return; QList::iterator iter; for (iter = graphParams.begin(); iter != graphParams.end(); ++iter) { - outFile->write("Z,"); - outFile->write(QString::number(iter->ID, 16).toUtf8()); - outFile->putChar(','); - outFile->write(QString::number(iter->mask, 16).toUtf8()); - outFile->putChar(','); - if (iter->intelFormat) outFile->write(QString::number(iter->startBit).toUtf8()); - else outFile->write(QString::number(iter->startBit * -1).toUtf8()); - outFile->putChar(','); - outFile->write(QString::number(iter->numBits).toUtf8()); - outFile->putChar(','); - if (iter->isSigned) outFile->putChar('Y'); - else outFile->putChar('N'); - outFile->putChar(','); - outFile->write(QString::number(iter->bias).toUtf8()); - outFile->putChar(','); - outFile->write(QString::number(iter->scale).toUtf8()); - outFile->putChar(','); - outFile->write(QString::number(iter->stride).toUtf8()); - outFile->putChar(','); - outFile->write(QString::number(iter->bus).toUtf8()); - outFile->putChar(','); - outFile->write(QString::number(iter->lineColor.red()).toUtf8()); - outFile->putChar(','); - outFile->write(QString::number(iter->lineColor.green()).toUtf8()); - outFile->putChar(','); - outFile->write(QString::number(iter->lineColor.blue()).toUtf8()); - outFile->putChar(','); - outFile->write(iter->graphName.toUtf8()); - outFile->putChar(','); - outFile->write(QString::number(iter->fillColor.red()).toUtf8()); - outFile->putChar(','); - outFile->write(QString::number(iter->fillColor.green()).toUtf8()); - outFile->putChar(','); - outFile->write(QString::number(iter->fillColor.blue()).toUtf8()); - outFile->putChar(','); - outFile->write(QString::number(iter->fillColor.alpha()).toUtf8()); - outFile->putChar(','); - if (iter->drawOnlyPoints) outFile->putChar('Y'); - else outFile->putChar('N'); - outFile->putChar(','); - outFile->write(QString::number(iter->pointType).toUtf8()); - outFile->putChar(','); - outFile->write(QString::number(iter->lineWidth).toUtf8()); + outFile.write("Z,"); + outFile.write(QString::number(iter->ID, 16).toUtf8()); + outFile.putChar(','); + outFile.write(QString::number(iter->mask, 16).toUtf8()); + outFile.putChar(','); + if (iter->intelFormat) outFile.write(QString::number(iter->startBit).toUtf8()); + else outFile.write(QString::number(iter->startBit * -1).toUtf8()); + outFile.putChar(','); + outFile.write(QString::number(iter->numBits).toUtf8()); + outFile.putChar(','); + if (iter->isSigned) outFile.putChar('Y'); + else outFile.putChar('N'); + outFile.putChar(','); + outFile.write(QString::number(iter->bias).toUtf8()); + outFile.putChar(','); + outFile.write(QString::number(iter->scale).toUtf8()); + outFile.putChar(','); + outFile.write(QString::number(iter->stride).toUtf8()); + outFile.putChar(','); + outFile.write(QString::number(iter->bus).toUtf8()); + outFile.putChar(','); + outFile.write(QString::number(iter->lineColor.red()).toUtf8()); + outFile.putChar(','); + outFile.write(QString::number(iter->lineColor.green()).toUtf8()); + outFile.putChar(','); + outFile.write(QString::number(iter->lineColor.blue()).toUtf8()); + outFile.putChar(','); + outFile.write(iter->graphName.toUtf8()); + outFile.putChar(','); + outFile.write(QString::number(iter->fillColor.red()).toUtf8()); + outFile.putChar(','); + outFile.write(QString::number(iter->fillColor.green()).toUtf8()); + outFile.putChar(','); + outFile.write(QString::number(iter->fillColor.blue()).toUtf8()); + outFile.putChar(','); + outFile.write(QString::number(iter->fillColor.alpha()).toUtf8()); + outFile.putChar(','); + if (iter->drawOnlyPoints) outFile.putChar('Y'); + else outFile.putChar('N'); + outFile.putChar(','); + outFile.write(QString::number(iter->pointType).toUtf8()); + outFile.putChar(','); + outFile.write(QString::number(iter->lineWidth).toUtf8()); if (iter->associatedSignal) { - outFile->putChar(','); - outFile->write(iter->associatedSignal->parentMessage->name.toUtf8()); - outFile->putChar(','); - outFile->write(iter->associatedSignal->name.toUtf8()); + outFile.putChar(','); + outFile.write(iter->associatedSignal->parentMessage->name.toUtf8()); + outFile.putChar(','); + outFile.write(iter->associatedSignal->name.toUtf8()); } - outFile->write("\n"); + outFile.write("\n"); } - outFile->close(); + outFile.close(); } } void GraphingWindow::loadDefinitions() { - QString filename; QFileDialog dialog; QSettings settings; @@ -971,17 +967,17 @@ void GraphingWindow::loadDefinitions() if (dialog.exec() == QDialog::Accepted) { - filename = dialog.selectedFiles()[0]; + QString filename = dialog.selectedFiles().constFirst(); settings.setValue("Graphing/LoadSaveDirectory", dialog.directory().path()); - QFile *inFile = new QFile(filename); + QFile inFile(filename); QByteArray line; - if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text)) + if (!inFile.open(QIODevice::ReadOnly | QIODevice::Text)) return; - while (!inFile->atEnd()) { - line = inFile->readLine().simplified(); + while (!inFile.atEnd()) { + line = inFile.readLine().simplified(); if (line.length() > 2) { GraphParams gp; @@ -1203,7 +1199,7 @@ void GraphingWindow::loadDefinitions() } } } - inFile->close(); + inFile.close(); } } diff --git a/re/newgraphdialog.cpp b/re/newgraphdialog.cpp index 6b759f49..62f73c66 100644 --- a/re/newgraphdialog.cpp +++ b/re/newgraphdialog.cpp @@ -361,7 +361,6 @@ void NewGraphDialog::loadNodes() void NewGraphDialog::loadMessages(int idx) { int numFiles = 0; - DBC_MESSAGE *msg; ui->cbMessages->clear(); if (dbcHandler == nullptr) return; if ((numFiles = dbcHandler->getFileCount()) == 0) return; From d0c508c0ea8b33f8e31013df2eca213f71c2ae22 Mon Sep 17 00:00:00 2001 From: Alexey Esaulenko Date: Thu, 18 Jan 2024 15:02:44 +0400 Subject: [PATCH 07/10] FrameSender: fix memory corruption while writing to the QCanBusFrame with empty payload --- framesenderwindow.cpp | 2 -- re/flowviewwindow.cpp | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/framesenderwindow.cpp b/framesenderwindow.cpp index 73162e56..a6e867cc 100644 --- a/framesenderwindow.cpp +++ b/framesenderwindow.cpp @@ -1054,8 +1054,6 @@ void FrameSenderWindow::processCellChange(int line, int col) } break; case ST_COLS::SENDTAB_COL_DATA: //Data bytes - for (int i = 0; i < 8; i++) sendingData[line].payload().data()[i] = 0; - #if QT_VERSION >= QT_VERSION_CHECK( 5, 14, 0 ) tokens = ui->tableSender->item(line, ST_COLS::SENDTAB_COL_DATA)->text().split(" ", Qt::SkipEmptyParts); #else diff --git a/re/flowviewwindow.cpp b/re/flowviewwindow.cpp index c51960b1..77c088f8 100644 --- a/re/flowviewwindow.cpp +++ b/re/flowviewwindow.cpp @@ -851,7 +851,7 @@ void FlowViewWindow::updatePosition(bool forward) int maxVal = qMin(chunk * 8 + 8, frameCache.at(currentPosition).payload().length()); for (int i = chunk * 8; i < maxVal; i++) { - unsigned char thisByte = static_cast(frameCache.at(currentPosition).payload().data()[i]); + unsigned char thisByte = static_cast(frameCache.at(currentPosition).payload()[i]); cngByte = currBytes[i] ^ thisByte; changedBits |= (uint64_t)cngByte << (8ull * (i & 7)); } From f98ee0a34dc6527f197939e105053040e364435a Mon Sep 17 00:00:00 2001 From: Alexey Esaulenko Date: Thu, 18 Jan 2024 15:13:48 +0400 Subject: [PATCH 08/10] SocketCANd: fix memory leak: string can be accessed after object destruction --- connections/socketcand.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/connections/socketcand.cpp b/connections/socketcand.cpp index 83fb144a..6ef89755 100644 --- a/connections/socketcand.cpp +++ b/connections/socketcand.cpp @@ -219,8 +219,8 @@ void SocketCANd::connectDevice() void SocketCANd::deviceConnected(int busNum) { sendDebug("Opening CAN on Kayak Device!"); - const char* openCanCmd = ("< open " + hostCanIDs[busNum] + " >").toStdString().c_str(); - sendStringToTCP(openCanCmd, busNum); + QString openCanCmd("< open " % hostCanIDs[busNum] % " >"); + sendStringToTCP(openCanCmd.toUtf8().data(), busNum); QCoreApplication::processEvents(); } @@ -383,8 +383,6 @@ void SocketCANd::procRXData(QString data, int busNum) mTimer.stop(); mTimer.start(); } - QByteArray output; - switch (rx_state.at(busNum)) { case IDLE: From 2b5aa1f111e1bde02f3a34185b948ddc2046682e Mon Sep 17 00:00:00 2001 From: Alexey Esaulenko Date: Thu, 18 Jan 2024 15:25:42 +0400 Subject: [PATCH 09/10] Minor: DBCComparatorWindow: sanity checks to fix gcc warnings --- re/dbccomparatorwindow.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/re/dbccomparatorwindow.cpp b/re/dbccomparatorwindow.cpp index e9b87b27..f8eb0bd9 100644 --- a/re/dbccomparatorwindow.cpp +++ b/re/dbccomparatorwindow.cpp @@ -222,8 +222,8 @@ void DBCComparatorWindow::calculateDetails() ui->treeDetails->addTopLevelItem(msgDiffRoot); - QTreeWidgetItem *msgItem; - QTreeWidgetItem *sigTemp; + QTreeWidgetItem *msgItem {}; + QTreeWidgetItem *sigTemp {}; for (int i = 0; i < firstDBC->messageHandler->getCount(); i++) { @@ -257,7 +257,8 @@ void DBCComparatorWindow::calculateDetails() msgItem->setText(0, msgName + " (" + Utility::formatCANID(thisMsg->ID) + ")"); sigDiffTwo->addChild(msgItem); } - msgItem->addChild(missingSigItem); + if (msgItem) + msgItem->addChild(missingSigItem); } else //signal exists on both sides. See if it as changed position or length { @@ -301,7 +302,8 @@ void DBCComparatorWindow::calculateDetails() sigTemp->setText(0, msgName + " (" + Utility::formatCANID(thisMsg->ID) + ")"); sigModifiedRoot->addChild(sigTemp); } - sigTemp->addChild(sigItem); + if (sigTemp) + sigTemp->addChild(sigItem); } } } From f634cd9e6cc5086bddabf69e81627f006d076b90 Mon Sep 17 00:00:00 2001 From: Alexey Esaulenko Date: Thu, 18 Jan 2024 18:42:06 +0400 Subject: [PATCH 10/10] Minor: SnifferWindow: fix deprecated constant --- re/sniffer/snifferwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/re/sniffer/snifferwindow.cpp b/re/sniffer/snifferwindow.cpp index e0ecfb87..f8145b14 100644 --- a/re/sniffer/snifferwindow.cpp +++ b/re/sniffer/snifferwindow.cpp @@ -181,7 +181,7 @@ void SnifferWindow::notchTick() } else { - ui->lblNotch->setBackgroundRole(QPalette::Background); + ui->lblNotch->setBackgroundRole(QPalette::Window); ui->lblNotch->repaint(); //qDebug() << "Tock"; }