mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-15 04:24:28 +00:00
common array: + exception handling.
properly handle if the realloc() is failed. @Isssue: https://github.com/Samsung/thorvg/issues/995
This commit is contained in:
parent
8608238343
commit
2aa551e222
1 changed files with 10 additions and 1 deletions
|
@ -38,7 +38,12 @@ struct Array
|
||||||
{
|
{
|
||||||
if (count + 1 > reserved) {
|
if (count + 1 > reserved) {
|
||||||
reserved = (count + 1) * 2;
|
reserved = (count + 1) * 2;
|
||||||
|
auto p = data;
|
||||||
data = static_cast<T*>(realloc(data, sizeof(T) * reserved));
|
data = static_cast<T*>(realloc(data, sizeof(T) * reserved));
|
||||||
|
if (!data) {
|
||||||
|
data = p;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
data[count++] = element;
|
data[count++] = element;
|
||||||
}
|
}
|
||||||
|
@ -47,8 +52,12 @@ struct Array
|
||||||
{
|
{
|
||||||
if (size > reserved) {
|
if (size > reserved) {
|
||||||
reserved = size;
|
reserved = size;
|
||||||
|
auto p = data;
|
||||||
data = static_cast<T*>(realloc(data, sizeof(T) * reserved));
|
data = static_cast<T*>(realloc(data, sizeof(T) * reserved));
|
||||||
if (!data) return false;
|
if (!data) {
|
||||||
|
data = p;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue