From c204b33314802d5e5719990d76bccc87a1907c9d Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 13 Apr 2024 18:50:33 +0200 Subject: [PATCH] VideoCommon/BPStructs: Add a missing bounds check Happened to find this when working on the previous commit. --- Source/Core/VideoCommon/BPStructs.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Source/Core/VideoCommon/BPStructs.cpp b/Source/Core/VideoCommon/BPStructs.cpp index 7eb6c88656..4f02c298b4 100644 --- a/Source/Core/VideoCommon/BPStructs.cpp +++ b/Source/Core/VideoCommon/BPStructs.cpp @@ -590,13 +590,16 @@ static void BPWritten(PixelShaderManager& pixel_shader_manager, XFStateManager& if (tmem_cfg.preload_tile_info.type != 3) { - bytes_read = tmem_cfg.preload_tile_info.count * TMEM_LINE_SIZE; - if (tmem_addr_even + bytes_read > TMEM_SIZE) - bytes_read = TMEM_SIZE - tmem_addr_even; + if (tmem_addr_even < TMEM_SIZE) + { + bytes_read = tmem_cfg.preload_tile_info.count * TMEM_LINE_SIZE; + if (tmem_addr_even + bytes_read > TMEM_SIZE) + bytes_read = TMEM_SIZE - tmem_addr_even; - auto& system = Core::System::GetInstance(); - auto& memory = system.GetMemory(); - memory.CopyFromEmu(s_tex_mem.data() + tmem_addr_even, src_addr, bytes_read); + auto& system = Core::System::GetInstance(); + auto& memory = system.GetMemory(); + memory.CopyFromEmu(s_tex_mem.data() + tmem_addr_even, src_addr, bytes_read); + } } else // RGBA8 tiles (and CI14, but that might just be stupid libogc!) {