mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-08-01 05:38:50 +00:00
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.
This commit is contained in:
parent
017f72f43e
commit
5c9bb80638
5 changed files with 53 additions and 25 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue