mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-25 23:59:12 +00:00
common canvas: return FailedAllocation if it really failed at memory allocation.
This fixes SwCanvasBase Reservation Unit Test.
This commit is contained in:
parent
ce6348a504
commit
f0ecc670ef
2 changed files with 4 additions and 2 deletions
|
@ -43,12 +43,14 @@ struct Array
|
||||||
data[count++] = element;
|
data[count++] = element;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reserve(uint32_t size)
|
bool reserve(uint32_t size)
|
||||||
{
|
{
|
||||||
if (size > reserved) {
|
if (size > reserved) {
|
||||||
reserved = size;
|
reserved = size;
|
||||||
data = static_cast<T*>(realloc(data, sizeof(T) * reserved));
|
data = static_cast<T*>(realloc(data, sizeof(T) * reserved));
|
||||||
|
if (!data) return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pop()
|
void pop()
|
||||||
|
|
|
@ -38,7 +38,7 @@ Canvas::~Canvas()
|
||||||
|
|
||||||
Result Canvas::reserve(uint32_t n) noexcept
|
Result Canvas::reserve(uint32_t n) noexcept
|
||||||
{
|
{
|
||||||
pImpl->paints.reserve(n);
|
if (!pImpl->paints.reserve(n)) return Result::FailedAllocation;
|
||||||
return Result::Success;
|
return Result::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue