ICU-1779 avoid malloc(0)

X-SVN-Rev: 8091
This commit is contained in:
Alan Liu 2002-03-18 21:25:01 +00:00
parent 0c30e75ab3
commit cd9a595ff6
3 changed files with 9 additions and 1 deletions

View file

@ -1364,6 +1364,9 @@ UnicodeString::handleReplaceBetween(int32_t start,
*/
void
UnicodeString::copy(int32_t start, int32_t limit, int32_t dest) {
if (limit <= start) {
return; // Nothing to do; avoid bogus malloc call
}
UChar* text = (UChar*) uprv_malloc( sizeof(UChar) * (limit - start) );
extractBetween(start, limit, text, 0);
insert(dest, text, 0, limit - start);

View file

@ -32,6 +32,10 @@ UVector::UVector(int32_t initialCapacity, UErrorCode &status) :
deleter(0),
comparer(0)
{
// Fix bogus initialCapacity values; avoid malloc(0)
if (initialCapacity < 1) {
initialCapacity = 1;
}
_init(initialCapacity, status);
}

View file

@ -276,8 +276,9 @@ void TransliterationRuleSet::freeze(UParseError& parseError,UErrorCode& status)
}
/* Precompute the index values. This saves a LOT of time.
* Be careful not to call malloc(0).
*/
int16_t* indexValue = (int16_t*) uprv_malloc( sizeof(int16_t) * n );
int16_t* indexValue = (int16_t*) uprv_malloc( sizeof(int16_t) * (n > 0 ? n : 1) );
for (j=0; j<n; ++j) {
TransliterationRule* r = (TransliterationRule*) ruleVector->elementAt(j);
indexValue[j] = r->getIndexValue();