common canvas: return FailedAllocation if it really failed at memory allocation.

This fixes SwCanvasBase Reservation Unit Test.
This commit is contained in:
Hermet Park 2021-06-07 20:04:39 +09:00
parent ce6348a504
commit f0ecc670ef
2 changed files with 4 additions and 2 deletions

View file

@ -43,12 +43,14 @@ struct Array
data[count++] = element;
}
void reserve(uint32_t size)
bool reserve(uint32_t size)
{
if (size > reserved) {
reserved = size;
data = static_cast<T*>(realloc(data, sizeof(T) * reserved));
if (!data) return false;
}
return true;
}
void pop()

View file

@ -38,7 +38,7 @@ Canvas::~Canvas()
Result Canvas::reserve(uint32_t n) noexcept
{
pImpl->paints.reserve(n);
if (!pImpl->paints.reserve(n)) return Result::FailedAllocation;
return Result::Success;
}