From cc83f395246492e2ed0e7c8e4594974cb9a46f48 Mon Sep 17 00:00:00 2001 From: Nav Date: Sat, 30 Oct 2021 14:46:57 +0100 Subject: [PATCH] Fixed bug with obsolete byte address items not being removed (off-by-one error) --- .../HexViewerWidget/ByteAddressContainer.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.cpp index b7e843a1..5844cc8d 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteAddressContainer.cpp @@ -18,9 +18,9 @@ void ByteAddressContainer::adjustAddressLabels( ) { static const auto margins = QMargins(0, 10, 0, 0); - const auto rowCount = byteItemsByRowIndex.size(); - const auto addressLabelCount = this->addressItemsByRowIndex.size(); - const auto layoutItemMaxIndex = static_cast(addressLabelCount - 1); + const auto newRowCount = byteItemsByRowIndex.size(); + const auto layoutItemMaxIndex = static_cast(this->addressItemsByRowIndex.size() - 1); + for (const auto& mappingPair : byteItemsByRowIndex) { const auto rowIndex = static_cast(mappingPair.first); const auto& byteWidgets = mappingPair.second; @@ -45,9 +45,11 @@ void ByteAddressContainer::adjustAddressLabels( ); } - if (rowCount > 0 && rowCount > byteItemsByRowIndex.size()) { - const auto rowCount = static_cast(byteItemsByRowIndex.size()); - for (std::size_t i = rowCount - 1; i >= rowCount; i--) { + // Delete any address items we no longer need + const auto addressItemCount = this->addressItemsByRowIndex.size(); + + if (newRowCount > 0 && newRowCount < addressItemCount) { + for (auto i = (addressItemCount - 1); i >= newRowCount; i--) { delete this->addressItemsByRowIndex.at(i); this->addressItemsByRowIndex.erase(i); }