Fix crash when copy constructing unhandled packets

Actually this is a workaround: it does not attempt to copy construct
unhandled packets, to avoid a bug in the base class where pointers were
copy constructed without copying the contents.

A proper fix will need refactoring of the packet storage code.
This commit is contained in:
Gavin MacGregor
2025-02-11 09:43:36 +00:00
parent df1122f621
commit b937102139
2 changed files with 8 additions and 2 deletions

View File

@@ -33,6 +33,7 @@ LevelOnePage::LevelOnePage()
clearPage(); clearPage();
} }
// BUG this copy constructor isn't used? Parameter should be LevelOnePage
LevelOnePage::LevelOnePage(const PageBase &other) LevelOnePage::LevelOnePage(const PageBase &other)
{ {
m_enhancements.reserve(maxEnhancements()); m_enhancements.reserve(maxEnhancements());
@@ -186,7 +187,9 @@ bool LevelOnePage::setPacket(int packetNumber, QByteArray packetContents)
} }
qDebug("LevelOnePage unhandled setPacket X/%d", packetNumber); qDebug("LevelOnePage unhandled setPacket X/%d", packetNumber);
return PageBase::setPacket(packetNumber, packetContents); // BUG can't store unhandled packets as default copy constructor uses pointers
//return PageBase::setPacket(packetNumber, packetContents);
return false;
} }
bool LevelOnePage::setPacket(int packetNumber, int designationCode, QByteArray packetContents) bool LevelOnePage::setPacket(int packetNumber, int designationCode, QByteArray packetContents)
@@ -253,7 +256,9 @@ bool LevelOnePage::setPacket(int packetNumber, int designationCode, QByteArray p
} }
qDebug("LevelOnePage unhandled setPacket X/%d/%d", packetNumber, designationCode); qDebug("LevelOnePage unhandled setPacket X/%d/%d", packetNumber, designationCode);
return PageBase::setPacket(packetNumber, designationCode, packetContents); // BUG can't store unhandled packets as default copy constructor uses pointers
//return PageBase::setPacket(packetNumber, designationCode, packetContents);
return false;
} }
bool LevelOnePage::packetExists(int packetNumber) const bool LevelOnePage::packetExists(int packetNumber) const

View File

@@ -36,6 +36,7 @@ public:
enum CycleTypeEnum { CTcycles, CTseconds }; enum CycleTypeEnum { CTcycles, CTseconds };
LevelOnePage(); LevelOnePage();
// BUG this copy constructor isn't used? Parameter should be LevelOnePage
LevelOnePage(const PageBase &other); LevelOnePage(const PageBase &other);
bool isEmpty() const override; bool isEmpty() const override;