mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-6076 Fix some allocation issues.
X-SVN-Rev: 23087
This commit is contained in:
parent
6112b5685d
commit
1725c5899a
6 changed files with 29 additions and 24 deletions
|
@ -945,7 +945,7 @@ void RBBITableBuilder::setAdd(UVector *dest, UVector *source) {
|
|||
(void) dest->toArray(destBuff);
|
||||
(void) source->toArray(sourceBuff);
|
||||
|
||||
dest->setSize(sourceSize+destOriginalSize);
|
||||
dest->setSize(sourceSize+destOriginalSize, *fStatus);
|
||||
|
||||
while (sourceBuff < sourceLim && destBuff < destLim) {
|
||||
if (*destBuff == *sourceBuff) {
|
||||
|
@ -970,7 +970,7 @@ void RBBITableBuilder::setAdd(UVector *dest, UVector *source) {
|
|||
dest->setElementAt(*sourceBuff++, di++);
|
||||
}
|
||||
|
||||
dest->setSize(di);
|
||||
dest->setSize(di, *fStatus);
|
||||
if (destH) {
|
||||
uprv_free(destH);
|
||||
}
|
||||
|
@ -1211,7 +1211,7 @@ RBBIStateDescriptor::RBBIStateDescriptor(int lastInputSymbol, UErrorCode *fStatu
|
|||
*fStatus = U_MEMORY_ALLOCATION_ERROR;
|
||||
return;
|
||||
}
|
||||
fDtran->setSize(lastInputSymbol+1); // fDtran needs to be pre-sized.
|
||||
fDtran->setSize(lastInputSymbol+1, *fStatus); // fDtran needs to be pre-sized.
|
||||
// It is indexed by input symbols, and will
|
||||
// hold the next state number for each
|
||||
// symbol.
|
||||
|
|
|
@ -1374,9 +1374,9 @@ private:
|
|||
// Implementation: Utility methods
|
||||
//----------------------------------------------------------------
|
||||
|
||||
void ensureCapacity(int32_t newLen);
|
||||
void ensureCapacity(int32_t newLen, UErrorCode& ec);
|
||||
|
||||
void ensureBufferCapacity(int32_t newLen);
|
||||
void ensureBufferCapacity(int32_t newLen, UErrorCode& ec);
|
||||
|
||||
void swapBuffers(void);
|
||||
|
||||
|
|
|
@ -144,12 +144,13 @@ UnicodeSet::UnicodeSet() :
|
|||
len(1), capacity(1 + START_EXTRA), list(0), bmpSet(0), buffer(0),
|
||||
bufferCapacity(0), patLen(0), pat(NULL), strings(NULL), stringSpan(NULL)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
allocateStrings(status);
|
||||
list = (UChar32*) uprv_malloc(sizeof(UChar32) * capacity);
|
||||
if(list!=NULL){
|
||||
list[0] = UNICODESET_HIGH;
|
||||
}
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
allocateStrings(status);
|
||||
// else TODO: we should set this to bogus on malloc failure.
|
||||
_dbgct(this);
|
||||
}
|
||||
|
||||
|
@ -164,14 +165,14 @@ UnicodeSet::UnicodeSet(UChar32 start, UChar32 end) :
|
|||
len(1), capacity(1 + START_EXTRA), list(0), bmpSet(0), buffer(0),
|
||||
bufferCapacity(0), patLen(0), pat(NULL), strings(NULL), stringSpan(NULL)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
allocateStrings(status);
|
||||
list = (UChar32*) uprv_malloc(sizeof(UChar32) * capacity);
|
||||
if(list!=NULL){
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
list[0] = UNICODESET_HIGH;
|
||||
allocateStrings(status);
|
||||
complement(start, end);
|
||||
}
|
||||
// else TODO: we should set this to bogus on malloc failure.
|
||||
_dbgct(this);
|
||||
}
|
||||
|
||||
|
@ -185,12 +186,13 @@ UnicodeSet::UnicodeSet(const UnicodeSet& o) :
|
|||
buffer(0), bufferCapacity(0),
|
||||
patLen(0), pat(NULL), strings(NULL), stringSpan(NULL)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
allocateStrings(status);
|
||||
list = (UChar32*) uprv_malloc(sizeof(UChar32) * capacity);
|
||||
if(list!=NULL){
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
allocateStrings(status);
|
||||
*this = o;
|
||||
}
|
||||
// else TODO: we should set this to bogus on malloc failure.
|
||||
_dbgct(this);
|
||||
}
|
||||
|
||||
|
@ -202,10 +204,11 @@ UnicodeSet::UnicodeSet(const UnicodeSet& o, UBool /* asThawed */) :
|
|||
buffer(0), bufferCapacity(0),
|
||||
patLen(0), pat(NULL), strings(NULL), stringSpan(NULL)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
allocateStrings(status);
|
||||
|
||||
list = (UChar32*) uprv_malloc(sizeof(UChar32) * capacity);
|
||||
if(list!=NULL){
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
allocateStrings(status);
|
||||
// *this = o except for bmpSet and stringSpan
|
||||
len = o.len;
|
||||
uprv_memcpy(list, o.list, len*sizeof(UChar32));
|
||||
|
@ -214,6 +217,7 @@ UnicodeSet::UnicodeSet(const UnicodeSet& o, UBool /* asThawed */) :
|
|||
setPattern(UnicodeString(o.pat, o.patLen));
|
||||
}
|
||||
}
|
||||
// else TODO: we should set this to bogus on malloc failure.
|
||||
_dbgct(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -93,12 +93,14 @@ UVector::~UVector() {
|
|||
*/
|
||||
void UVector::assign(const UVector& other, UTokenAssigner *assign, UErrorCode &ec) {
|
||||
if (ensureCapacity(other.count, ec)) {
|
||||
setSize(other.count);
|
||||
for (int32_t i=0; i<other.count; ++i) {
|
||||
if (elements[i].pointer != 0 && deleter != 0) {
|
||||
(*deleter)(elements[i].pointer);
|
||||
setSize(other.count, ec);
|
||||
if (U_SUCCESS(ec)) {
|
||||
for (int32_t i=0; i<other.count; ++i) {
|
||||
if (elements[i].pointer != 0 && deleter != 0) {
|
||||
(*deleter)(elements[i].pointer);
|
||||
}
|
||||
(*assign)(&elements[i], &other.elements[i]);
|
||||
}
|
||||
(*assign)(&elements[i], &other.elements[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -346,14 +348,13 @@ UBool UVector::ensureCapacity(int32_t minimumCapacity, UErrorCode &status) {
|
|||
* newSize. If newSize is larger, grow the array, filling in new
|
||||
* slots with NULL.
|
||||
*/
|
||||
void UVector::setSize(int32_t newSize) {
|
||||
void UVector::setSize(int32_t newSize, UErrorCode &status) {
|
||||
int32_t i;
|
||||
if (newSize < 0) {
|
||||
return;
|
||||
}
|
||||
if (newSize > count) {
|
||||
UErrorCode ec = U_ZERO_ERROR;
|
||||
if (!ensureCapacity(newSize, ec)) {
|
||||
if (!ensureCapacity(newSize, status)) {
|
||||
return;
|
||||
}
|
||||
UHashTok empty;
|
||||
|
|
|
@ -195,7 +195,7 @@ public:
|
|||
* elements for i >= newSize. If newSize is larger, grow the
|
||||
* array, filling in new slots with NULL.
|
||||
*/
|
||||
void setSize(int32_t newSize);
|
||||
void setSize(int32_t newSize, UErrorCode &status);
|
||||
|
||||
/**
|
||||
* Fill in the given array with all elements of this vector.
|
||||
|
|
|
@ -1508,7 +1508,7 @@ void TransliteratorParser::setSegmentObject(int32_t seg, StringMatcher* adopted,
|
|||
// and stored before segment i; be careful with the
|
||||
// vector handling here.
|
||||
if (segmentObjects.size() < seg) {
|
||||
segmentObjects.setSize(seg);
|
||||
segmentObjects.setSize(seg, status);
|
||||
}
|
||||
int32_t index = getSegmentStandin(seg, status) - curData->variablesBase;
|
||||
if (segmentObjects.elementAt(seg-1) != NULL ||
|
||||
|
|
Loading…
Add table
Reference in a new issue