mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-09 03:10:22 +00:00
TINYGL: Added safety checks to Linear Allocator.
This commit is contained in:
parent
957fa20c30
commit
e1aea3a1f3
@ -214,6 +214,9 @@ public:
|
||||
void initialize(size_t newSize) {
|
||||
assert(_memoryBuffer == nullptr);
|
||||
void *newBuffer = gl_malloc(newSize);
|
||||
if (newBuffer == nullptr) {
|
||||
error("Couldn't allocate memory for linear allocator.");
|
||||
}
|
||||
_memoryBuffer = newBuffer;
|
||||
_memorySize = newSize;
|
||||
}
|
||||
@ -225,7 +228,9 @@ public:
|
||||
}
|
||||
|
||||
void *allocate(size_t size) {
|
||||
assert (_memoryPosition + size < _memorySize);
|
||||
if (_memoryPosition + size >= _memorySize) {
|
||||
error("Allocator out of memory: couldn't allocate more memory from linear allocator.");
|
||||
}
|
||||
int returnPos = _memoryPosition;
|
||||
_memoryPosition += size;
|
||||
return ((char *)_memoryBuffer) + returnPos;
|
||||
|
Loading…
Reference in New Issue
Block a user