summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/TextureInfo.cpp
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2024-04-13 12:08:43 +0200
committerJosJuice <josjuice@gmail.com>2024-04-20 18:31:08 +0200
commit5c9bb80638ec05b32eaa129a8c763ac6bb3a5cb4 (patch)
tree06d56af0aa8a7328057cf133c8b93738f60412bc /Source/Core/VideoCommon/TextureInfo.cpp
parent017f72f43e6250697f1983c8ab6b692d0180d26c (diff)
Memmap: Replace GetPointer with GetSpanForAddress
To ensure memory safety, callers of GetPointer have to perform a bounds check. But how is this bounds check supposed to be performed? GetPointerForRange contained one implementation of a bounds check, but it was cumbersome, and it also isn't obvious why it's correct. To make doing the right thing easier, this commit changes GetPointer to return a span that tells the caller how many bytes it's allowed to access.
Diffstat (limited to 'Source/Core/VideoCommon/TextureInfo.cpp')
-rw-r--r--Source/Core/VideoCommon/TextureInfo.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/Source/Core/VideoCommon/TextureInfo.cpp b/Source/Core/VideoCommon/TextureInfo.cpp
index b73461ba33..a1bccb0ebe 100644
--- a/Source/Core/VideoCommon/TextureInfo.cpp
+++ b/Source/Core/VideoCommon/TextureInfo.cpp
@@ -3,6 +3,8 @@
#include "VideoCommon/TextureInfo.h"
+#include <span>
+
#include <fmt/format.h>
#include <xxhash.h>
@@ -47,8 +49,10 @@ TextureInfo TextureInfo::FromStage(u32 stage)
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
- return TextureInfo(stage, memory.GetPointer(address), tlut_ptr, address, texture_format,
- tlut_format, width, height, false, nullptr, nullptr, mip_count);
+ // TODO: For memory safety, we need to check the size of this span
+ std::span<const u8> span = memory.GetSpanForAddress(address);
+ return TextureInfo(stage, span.data(), tlut_ptr, address, texture_format, tlut_format, width,
+ height, false, nullptr, nullptr, mip_count);
}
TextureInfo::TextureInfo(u32 stage, const u8* ptr, const u8* tlut_ptr, u32 address,