mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 06:25:30 +00:00
ICU-1779 avoid malloc(0)
X-SVN-Rev: 8091
This commit is contained in:
parent
0c30e75ab3
commit
cd9a595ff6
3 changed files with 9 additions and 1 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue