Merge pull request #3291 from JosJuice/memset-error-check
Memmap: More error checking for Memset
This commit is contained in:
commit
861bd98e3a
|
@ -244,11 +244,18 @@ bool AreMemoryBreakpointsActivated()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool ValidCopyRange(u32 address, size_t size)
|
static inline u8* GetPointerForRange(u32 address, size_t size)
|
||||||
{
|
{
|
||||||
return (GetPointer(address) != nullptr &&
|
// Make sure we don't have a range spanning 2 separate banks
|
||||||
GetPointer(address + u32(size) - 1) != nullptr &&
|
if (size >= EXRAM_SIZE)
|
||||||
size < EXRAM_SIZE); // Make sure we don't have a range spanning 2 separate banks
|
return nullptr;
|
||||||
|
|
||||||
|
// Check that the beginning and end of the range are valid
|
||||||
|
u8* pointer = GetPointer(address);
|
||||||
|
if (!pointer || !GetPointer(address + u32(size) - 1))
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CopyFromEmu(void* data, u32 address, size_t size)
|
void CopyFromEmu(void* data, u32 address, size_t size)
|
||||||
|
@ -256,12 +263,13 @@ void CopyFromEmu(void* data, u32 address, size_t size)
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!ValidCopyRange(address, size))
|
void* pointer = GetPointerForRange(address, size);
|
||||||
|
if (!pointer)
|
||||||
{
|
{
|
||||||
PanicAlert("Invalid range in CopyFromEmu. %zx bytes from 0x%08x", size, address);
|
PanicAlert("Invalid range in CopyFromEmu. %zx bytes from 0x%08x", size, address);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
memcpy(data, GetPointer(address), size);
|
memcpy(data, pointer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CopyToEmu(u32 address, const void* data, size_t size)
|
void CopyToEmu(u32 address, const void* data, size_t size)
|
||||||
|
@ -269,22 +277,27 @@ void CopyToEmu(u32 address, const void* data, size_t size)
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!ValidCopyRange(address, size))
|
void* pointer = GetPointerForRange(address, size);
|
||||||
|
if (!pointer)
|
||||||
{
|
{
|
||||||
PanicAlert("Invalid range in CopyToEmu. %zx bytes to 0x%08x", size, address);
|
PanicAlert("Invalid range in CopyToEmu. %zx bytes to 0x%08x", size, address);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
memcpy(GetPointer(address), data, size);
|
memcpy(pointer, data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Memset(const u32 _Address, const u8 _iValue, const u32 _iLength)
|
void Memset(u32 address, u8 value, size_t size)
|
||||||
{
|
{
|
||||||
if (_iLength == 0)
|
if (size == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
u8* ptr = GetPointer(_Address);
|
void* pointer = GetPointerForRange(address, size);
|
||||||
if (ptr != nullptr)
|
if (!pointer)
|
||||||
memset(ptr, _iValue, _iLength);
|
{
|
||||||
|
PanicAlert("Invalid range in Memset. %zx bytes at 0x%08x", size, address);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
memset(pointer, value, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetString(u32 em_address, size_t size)
|
std::string GetString(u32 em_address, size_t size)
|
||||||
|
|
|
@ -80,7 +80,7 @@ std::string GetString(u32 em_address, size_t size = 0);
|
||||||
u8* GetPointer(const u32 address);
|
u8* GetPointer(const u32 address);
|
||||||
void CopyFromEmu(void* data, u32 address, size_t size);
|
void CopyFromEmu(void* data, u32 address, size_t size);
|
||||||
void CopyToEmu(u32 address, const void* data, size_t size);
|
void CopyToEmu(u32 address, const void* data, size_t size);
|
||||||
void Memset(const u32 address, const u8 var, const u32 length);
|
void Memset(u32 address, u8 value, size_t size);
|
||||||
u8 Read_U8(const u32 address);
|
u8 Read_U8(const u32 address);
|
||||||
u16 Read_U16(const u32 address);
|
u16 Read_U16(const u32 address);
|
||||||
u32 Read_U32(const u32 address);
|
u32 Read_U32(const u32 address);
|
||||||
|
|
Loading…
Reference in New Issue