Qt: Actually bounds check memory block index

This commit is contained in:
Vicki Pfau 2020-11-02 01:01:17 -08:00
parent 5a1e68beba
commit 01e73bc15f
1 changed files with 8 additions and 1 deletions

View File

@ -207,6 +207,9 @@ void MemoryView::setIndex(int index) {
mCore* core = m_controller->thread()->core;
const mCoreMemoryBlock* blocks;
size_t nBlocks = core->listMemoryBlocks(core, &blocks);
if (index < 0 || static_cast<size_t>(index) >= nBlocks) {
return;
}
const mCoreMemoryBlock& info = blocks[index];
m_region = qMakePair(info.start, info.end);
@ -221,7 +224,11 @@ void MemoryView::setSegment(int segment) {
mCore* core = m_controller->thread()->core;
const mCoreMemoryBlock* blocks;
size_t nBlocks = core->listMemoryBlocks(core, &blocks);
const mCoreMemoryBlock& info = blocks[m_ui.regions->currentIndex()];
int index = m_ui.regions->currentIndex();
if (index < 0 || static_cast<size_t>(index) >= nBlocks) {
return;
}
const mCoreMemoryBlock& info = blocks[index];
m_ui.hexfield->setSegment(info.maxSegment < segment ? info.maxSegment : segment);
}