From d7ef5a85dce4f91d99ec28b1ef27acb990833558 Mon Sep 17 00:00:00 2001 From: digant73 Date: Sat, 26 Apr 2025 19:39:02 +0200 Subject: [PATCH] fix missing check on swapped item --- rpcs3/Emu/RSX/Common/simple_array.hpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/simple_array.hpp b/rpcs3/Emu/RSX/Common/simple_array.hpp index 04a2ec9214..a567253f74 100644 --- a/rpcs3/Emu/RSX/Common/simple_array.hpp +++ b/rpcs3/Emu/RSX/Common/simple_array.hpp @@ -390,22 +390,21 @@ namespace rsx } bool ret = false; - for (auto ptr = _data, last = _data + (_size - 1); ptr <= last; ptr++) + for (auto last = _data + (_size - 1), ptr = last; ptr >= _data; ptr--) { if (predicate(*ptr)) { ret = true; - if (ptr == last) + if (ptr != last) // If not last { - // Popping the last entry from list. Just set the new size and exit - _size--; - break; + // Move last item into current one + std::memcpy(ptr, last, sizeof(Ty)); } - // Move item to the end of the list and shrink by 1 - std::memcpy(ptr, last, sizeof(Ty)); - last = _data + (--_size - 1); // set new last + // Pop last entry from list and set new last item + _size--; + last--; } }