mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-06 06:32:56 +01:00
Add Memory::Copy overlap check and Memory::Move
This commit is contained in:
@@ -16,10 +16,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "../common.h"
|
||||
}
|
||||
#include "../common.h"
|
||||
#include "Guard.hpp"
|
||||
|
||||
/**
|
||||
* Utility methods for memory management. Typically helpers and wrappers around the C standard library.
|
||||
@@ -80,9 +78,23 @@ namespace Memory
|
||||
T * Copy(T * dst, const T * src, size_t size)
|
||||
{
|
||||
if (size == 0) return (T*)dst;
|
||||
#ifdef DEBUG
|
||||
uintptr_t srcBegin = (uintptr_t)src;
|
||||
uintptr_t srcEnd = srcBegin + size;
|
||||
uintptr_t dstBegin = (uintptr_t)dst;
|
||||
uintptr_t dstEnd = dstBegin + size;
|
||||
Guard::Assert(srcEnd <= dstBegin || srcBegin >= dstEnd, "Source overlaps destination, try using Memory::Move.");
|
||||
#endif
|
||||
return (T*)memcpy((void*)dst, (const void*)src, size);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T * Move(T * dst, const T * src, size_t size)
|
||||
{
|
||||
if (size == 0) return (T*)dst;
|
||||
return (T*)memmove((void*)dst, (const void*)src, size);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T * Duplicate(const T * src, size_t size)
|
||||
{
|
||||
|
||||
@@ -251,7 +251,7 @@ namespace String
|
||||
assert(newStringSize < currentStringSize);
|
||||
#endif
|
||||
|
||||
Memory::Copy(str, firstNonWhitespace, newStringSize);
|
||||
Memory::Move(str, firstNonWhitespace, newStringSize);
|
||||
str[newStringSize] = '\0';
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user