summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/Software/TextureSampler.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/VideoBackends/Software/TextureSampler.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/VideoBackends/Software/TextureSampler.cpp')
-rw-r--r--Source/Core/VideoBackends/Software/TextureSampler.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/Source/Core/VideoBackends/Software/TextureSampler.cpp b/Source/Core/VideoBackends/Software/TextureSampler.cpp
index d5222384f0..f9182441bb 100644
--- a/Source/Core/VideoBackends/Software/TextureSampler.cpp
+++ b/Source/Core/VideoBackends/Software/TextureSampler.cpp
@@ -5,6 +5,7 @@
#include <algorithm>
#include <cmath>
+#include <span>
#include "Common/CommonTypes.h"
#include "Common/MsgHandler.h"
@@ -137,7 +138,9 @@ void SampleMip(s32 s, s32 t, s32 mip, bool linear, u8 texmap, u8* sample)
auto& memory = system.GetMemory();
const u32 imageBase = texUnit.texImage3.image_base << 5;
- imageSrc = memory.GetPointer(imageBase);
+ // TODO: For memory safety, we need to check the size of this span
+ std::span<const u8> span = memory.GetSpanForAddress(imageBase);
+ imageSrc = span.data();
}
int image_width_minus_1 = ti0.width;