From 3b72d78ec24dac7ddc00b8138ecb803d30d395ff Mon Sep 17 00:00:00 2001 From: Sour Date: Fri, 13 Oct 2023 17:15:15 +0900 Subject: [PATCH] Debugger: Memory Viewer - Fixed infinite loop when searching from the end of memory with a value longer than the amount of bytes left until the end --- UI/Debugger/ViewModels/MemoryToolsViewModel.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/UI/Debugger/ViewModels/MemoryToolsViewModel.cs b/UI/Debugger/ViewModels/MemoryToolsViewModel.cs index bbb01b742..1ae4ecec2 100644 --- a/UI/Debugger/ViewModels/MemoryToolsViewModel.cs +++ b/UI/Debugger/ViewModels/MemoryToolsViewModel.cs @@ -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) @@ -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) {