Handle out of memory conditions in the constructors more gracefully. We might end up using set_size() for every allocation (would probably make more sense)

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14722 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2005-11-06 22:49:19 +00:00
parent 84063c1f44
commit b0f02f2065

View File

@ -49,15 +49,20 @@
#include <RegionSupport.h>
const static int32 kInitialDataSize = 8;
/*! \brief Initializes a region. The region will have no rects,
and its bound will be invalid.
*/
BRegion::BRegion()
:
data_size(8),
data_size(0),
data(NULL)
{
data = (clipping_rect *)malloc(data_size * sizeof(clipping_rect));
data = (clipping_rect *)malloc(kInitialDataSize * sizeof(clipping_rect));
if (data != NULL)
data_size = kInitialDataSize;
Support::ZeroRegion(*this);
}
@ -68,18 +73,19 @@ BRegion::BRegion()
*/
BRegion::BRegion(const BRegion &region)
:
data_size(0),
data(NULL)
{
const int32 size = region.data_size > 0 ? region.data_size : 1;
data = (clipping_rect *)malloc(size * sizeof(clipping_rect));
if (data != NULL) {
data_size = size;
bound = region.bound;
count = region.count;
data_size = region.data_size;
if (data_size <= 0)
data_size = 1;
data = (clipping_rect *)malloc(data_size * sizeof(clipping_rect));
memcpy(data, region.data, count * sizeof(clipping_rect));
} else
Support::ZeroRegion(*this);
}
@ -88,12 +94,15 @@ BRegion::BRegion(const BRegion &region)
*/
BRegion::BRegion(const BRect rect)
:
data_size(8),
data_size(0),
data(NULL)
{
data = (clipping_rect *)malloc(data_size * sizeof(clipping_rect));
data = (clipping_rect *)malloc(kInitialDataSize * sizeof(clipping_rect));
if (data != NULL) {
data_size = kInitialDataSize;
Set(rect);
} else
Support::ZeroRegion(*this);
}