Skip to content

Commit

Permalink
Debugger: Memory Viewer - Fixed infinite loop when searching from the…
Browse files Browse the repository at this point in the history
… end of memory with a value longer than the amount of bytes left until the end
  • Loading branch information
SourMesen committed Oct 13, 2023
1 parent 6421069 commit 3b72d78
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions UI/Debugger/ViewModels/MemoryToolsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,6 @@ public bool Find(SearchDirection direction)
int searchLen = data.Data.Length;

int startPos = endPos + ((direction == SearchDirection.Backward || SelectionLength != 0) ? offset : 0);
if(startPos < 0) {
//Wrap around to the end
startPos = memSize - searchLen;
}

//TODO this can be a bit slow in edge cases depending on search+filters.
//(e.g search 00 00 00 in a code segment with no matches)
Expand All @@ -253,10 +249,16 @@ public bool Find(SearchDirection direction)
i = 0;
}

if(!firstLoop && i == startPos) {
break;
if(firstLoop) {
//Adjust startPos based on wrap around calculated above
startPos = i;
firstLoop = false;
} else {
if(i == startPos) {
//Break if all start positions were checked
break;
}
}
firstLoop = false;

int j = 0;
while(j < searchLen && i + j < memSize) {
Expand Down

0 comments on commit 3b72d78

Please sign in to comment.