Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions icu4c/source/common/localematcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ LocaleMatcher::LocaleMatcher(const Builder &builder, UErrorCode &errorCode) :
// so that when different types are used (e.g., language tag strings)
// we can return those by parallel index.
supportedLocales = static_cast<const Locale **>(
uprv_malloc(supportedLocalesLength * sizeof(const Locale *)));
uprv_calloc(supportedLocalesLength, sizeof(const Locale *)));
// Supported LRSs in input order.
// In C++, we store these permanently to simplify ownership management
// in the hash tables. Duplicate LSRs (if any) are unused overhead.
Expand Down Expand Up @@ -406,9 +406,9 @@ LocaleMatcher::LocaleMatcher(const Builder &builder, UErrorCode &errorCode) :
supportedLocalesLength, &errorCode);
if (U_FAILURE(errorCode)) { return; }
supportedLSRs = static_cast<const LSR **>(
uprv_malloc(supportedLocalesLength * sizeof(const LSR *)));
uprv_calloc(supportedLocalesLength, sizeof(const LSR *)));
supportedIndexes = static_cast<int32_t *>(
uprv_malloc(supportedLocalesLength * sizeof(int32_t)));
uprv_calloc(supportedLocalesLength, sizeof(int32_t)));
if (supportedLSRs == nullptr || supportedIndexes == nullptr) {
errorCode = U_MEMORY_ALLOCATION_ERROR;
return;
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/common/loclikelysubtags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ struct LikelySubtagsData {

if (partitionsLength > 0) {
distanceData.partitions = static_cast<const char **>(
uprv_malloc(partitionsLength * sizeof(const char *)));
uprv_calloc(partitionsLength, sizeof(const char *)));
if (distanceData.partitions == nullptr) {
errorCode = U_MEMORY_ALLOCATION_ERROR;
return;
Expand Down
8 changes: 4 additions & 4 deletions icu4c/source/common/rbbi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ RuleBasedBreakIterator::RuleBasedBreakIterator(RBBIDataHeader* data, UErrorCode
}
if (fData->fForwardTable->fLookAheadResultsSize > 0) {
fLookAheadMatches = static_cast<int32_t *>(
uprv_malloc(fData->fForwardTable->fLookAheadResultsSize * sizeof(int32_t)));
uprv_calloc(fData->fForwardTable->fLookAheadResultsSize, sizeof(int32_t)));
if (fLookAheadMatches == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
Expand Down Expand Up @@ -123,7 +123,7 @@ RuleBasedBreakIterator::RuleBasedBreakIterator(const uint8_t *compiledRules,
}
if (fData->fForwardTable->fLookAheadResultsSize > 0) {
fLookAheadMatches = static_cast<int32_t *>(
uprv_malloc(fData->fForwardTable->fLookAheadResultsSize * sizeof(int32_t)));
uprv_calloc(fData->fForwardTable->fLookAheadResultsSize, sizeof(int32_t)));
if (fLookAheadMatches == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
Expand All @@ -149,7 +149,7 @@ RuleBasedBreakIterator::RuleBasedBreakIterator(UDataMemory* udm, UErrorCode &sta
}
if (fData->fForwardTable->fLookAheadResultsSize > 0) {
fLookAheadMatches = static_cast<int32_t *>(
uprv_malloc(fData->fForwardTable->fLookAheadResultsSize * sizeof(int32_t)));
uprv_calloc(fData->fForwardTable->fLookAheadResultsSize, sizeof(int32_t)));
if (fLookAheadMatches == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
Expand Down Expand Up @@ -319,7 +319,7 @@ RuleBasedBreakIterator::operator=(const RuleBasedBreakIterator& that) {
fLookAheadMatches = nullptr;
if (fData && fData->fForwardTable->fLookAheadResultsSize > 0) {
fLookAheadMatches = static_cast<int32_t *>(
uprv_malloc(fData->fForwardTable->fLookAheadResultsSize * sizeof(int32_t)));
uprv_calloc(fData->fForwardTable->fLookAheadResultsSize, sizeof(int32_t)));
}


Expand Down
4 changes: 2 additions & 2 deletions icu4c/source/common/ucnvsel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ ucnvsel_open(const char* const* converterList, int32_t converterListSize,
converterListSize = ucnv_countAvailable();
}
newSelector->encodings =
(char**)uprv_malloc(converterListSize * sizeof(char*));
(char**)uprv_calloc(converterListSize, sizeof(char*));
if (!newSelector->encodings) {
*status = U_MEMORY_ALLOCATION_ERROR;
return nullptr;
Expand Down Expand Up @@ -716,7 +716,7 @@ static UEnumeration *selectForMask(const UConverterSelector* sel,
int16_t numOnes = countOnes(mask.getAlias(), columns);
// now, we know the exact space we need for index
if (numOnes > 0) {
result->index = static_cast<int16_t*>(uprv_malloc(numOnes * sizeof(int16_t)));
result->index = static_cast<int16_t*>(uprv_calloc(numOnes, sizeof(int16_t)));
if (result->index == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
return nullptr;
Expand Down
16 changes: 8 additions & 8 deletions icu4c/source/common/uidna.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ _internal_toASCII(const char16_t* src, int32_t srcLength,
}

if(srcLength > b1Capacity){
b1 = static_cast<char16_t*>(uprv_malloc(srcLength * U_SIZEOF_UCHAR));
b1 = static_cast<char16_t*>(uprv_calloc(srcLength, U_SIZEOF_UCHAR));
if(b1==nullptr){
*status = U_MEMORY_ALLOCATION_ERROR;
goto CLEANUP;
Expand Down Expand Up @@ -257,7 +257,7 @@ _internal_toASCII(const char16_t* src, int32_t srcLength,
if(b1 != b1Stack){
uprv_free(b1);
}
b1 = static_cast<char16_t*>(uprv_malloc(b1Len * U_SIZEOF_UCHAR));
b1 = static_cast<char16_t*>(uprv_calloc(b1Len, U_SIZEOF_UCHAR));
if(b1==nullptr){
*status = U_MEMORY_ALLOCATION_ERROR;
goto CLEANUP;
Expand Down Expand Up @@ -343,7 +343,7 @@ _internal_toASCII(const char16_t* src, int32_t srcLength,
if(bufferStatus == U_BUFFER_OVERFLOW_ERROR){
// redo processing of string
/* we do not have enough room so grow the buffer*/
b2 = static_cast<char16_t*>(uprv_malloc(b2Len * U_SIZEOF_UCHAR));
b2 = static_cast<char16_t*>(uprv_calloc(b2Len, U_SIZEOF_UCHAR));
if(b2 == nullptr){
*status = U_MEMORY_ALLOCATION_ERROR;
goto CLEANUP;
Expand Down Expand Up @@ -465,7 +465,7 @@ _internal_toUnicode(const char16_t* src, int32_t srcLength,
if(bufferStatus == U_BUFFER_OVERFLOW_ERROR){
// redo processing of string
/* we do not have enough room so grow the buffer*/
b1 = static_cast<char16_t*>(uprv_malloc(b1Len * U_SIZEOF_UCHAR));
b1 = static_cast<char16_t*>(uprv_calloc(b1Len, U_SIZEOF_UCHAR));
if(b1==nullptr){
*status = U_MEMORY_ALLOCATION_ERROR;
goto CLEANUP;
Expand Down Expand Up @@ -507,7 +507,7 @@ _internal_toUnicode(const char16_t* src, int32_t srcLength,
if(bufferStatus == U_BUFFER_OVERFLOW_ERROR){
// redo processing of string
/* we do not have enough room so grow the buffer*/
b2 = static_cast<char16_t*>(uprv_malloc(b2Len * U_SIZEOF_UCHAR));
b2 = static_cast<char16_t*>(uprv_calloc(b2Len, U_SIZEOF_UCHAR));
if(b2==nullptr){
*status = U_MEMORY_ALLOCATION_ERROR;
goto CLEANUP;
Expand All @@ -525,7 +525,7 @@ _internal_toUnicode(const char16_t* src, int32_t srcLength,
if(bufferStatus == U_BUFFER_OVERFLOW_ERROR){
// redo processing of string
/* we do not have enough room so grow the buffer*/
b3 = static_cast<char16_t*>(uprv_malloc(b3Len * U_SIZEOF_UCHAR));
b3 = static_cast<char16_t*>(uprv_calloc(b3Len, U_SIZEOF_UCHAR));
if(b3==nullptr){
*status = U_MEMORY_ALLOCATION_ERROR;
goto CLEANUP;
Expand Down Expand Up @@ -888,7 +888,7 @@ uidna_compare( const char16_t *s1, int32_t length1,
b1Len = uidna_IDNToASCII(s1, length1, b1, b1Capacity, options, &parseError, &bufferStatus);
if(bufferStatus == U_BUFFER_OVERFLOW_ERROR){
// redo processing of string
b1 = (char16_t*) uprv_malloc(b1Len * U_SIZEOF_UCHAR);
b1 = (char16_t*) uprv_calloc(b1Len, U_SIZEOF_UCHAR);
if(b1==nullptr){
*status = U_MEMORY_ALLOCATION_ERROR;
goto CLEANUP;
Expand All @@ -902,7 +902,7 @@ uidna_compare( const char16_t *s1, int32_t length1,
b2Len = uidna_IDNToASCII(s2,length2, b2,b2Capacity, options, &parseError, &bufferStatus);
if(bufferStatus == U_BUFFER_OVERFLOW_ERROR){
// redo processing of string
b2 = (char16_t*) uprv_malloc(b2Len * U_SIZEOF_UCHAR);
b2 = (char16_t*) uprv_calloc(b2Len, U_SIZEOF_UCHAR);
if(b2==nullptr){
*status = U_MEMORY_ALLOCATION_ERROR;
goto CLEANUP;
Expand Down
4 changes: 2 additions & 2 deletions icu4c/source/common/uniset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1644,7 +1644,7 @@ bool UnicodeSet::ensureCapacity(int32_t newLen) {
return true;
}
int32_t newCapacity = nextCapacity(newLen);
UChar32* temp = static_cast<UChar32*>(uprv_malloc(newCapacity * sizeof(UChar32)));
UChar32* temp = static_cast<UChar32*>(uprv_calloc(newCapacity, sizeof(UChar32)));
if (temp == nullptr) {
setToBogus(); // set the object to bogus state if an OOM failure occurred.
return false;
Expand All @@ -1667,7 +1667,7 @@ bool UnicodeSet::ensureBufferCapacity(int32_t newLen) {
return true;
}
int32_t newCapacity = nextCapacity(newLen);
UChar32* temp = static_cast<UChar32*>(uprv_malloc(newCapacity * sizeof(UChar32)));
UChar32* temp = static_cast<UChar32*>(uprv_calloc(newCapacity, sizeof(UChar32)));
if (temp == nullptr) {
setToBogus();
return false;
Expand Down
4 changes: 2 additions & 2 deletions icu4c/source/common/ustr_wcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ u_growAnyBufferFromStatic(void *context,
int32_t length, int32_t size) {
// Use char* not void* to avoid the compiler's strict-aliasing assumptions
// and related warnings.
char *newBuffer=(char *)uprv_malloc(reqCapacity*size);
char *newBuffer=(char *)uprv_calloc(reqCapacity, size);
if(newBuffer!=nullptr) {
if(length>0) {
uprv_memcpy(newBuffer, *pBuffer, (size_t)length*size);
Expand Down Expand Up @@ -146,7 +146,7 @@ _strToWCS(wchar_t *dest,
* no more than 2 wchar_ts
*/
intTargetCapacity = (count * _BUFFER_CAPACITY_MULTIPLIER + 1) /*for null termination */;
intTarget = (wchar_t*)uprv_malloc( intTargetCapacity * sizeof(wchar_t) );
intTarget = (wchar_t*)uprv_calloc( intTargetCapacity, sizeof(wchar_t) );

if(intTarget){

Expand Down
6 changes: 3 additions & 3 deletions icu4c/source/i18n/timezone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ static void U_CALLCONV initMap(USystemTimeZoneType type, UErrorCode& ec) {
res = ures_getByKey(res, kNAMES, res, &ec); // dereference Zones section
if (U_SUCCESS(ec)) {
int32_t size = ures_getSize(res);
int32_t* m = static_cast<int32_t*>(uprv_malloc(size * sizeof(int32_t)));
int32_t* m = static_cast<int32_t*>(uprv_calloc(size, sizeof(int32_t)));
if (m == nullptr) {
ec = U_MEMORY_ALLOCATION_ERROR;
} else {
Expand Down Expand Up @@ -845,7 +845,7 @@ class TZEnumeration : public StringEnumeration {

if (region != nullptr || rawOffset != nullptr) {
int32_t filteredMapSize = DEFAULT_FILTERED_MAP_SIZE;
filteredMap = static_cast<int32_t*>(uprv_malloc(filteredMapSize * sizeof(int32_t)));
filteredMap = static_cast<int32_t*>(uprv_calloc(filteredMapSize, sizeof(int32_t)));
if (filteredMap == nullptr) {
ec = U_MEMORY_ALLOCATION_ERROR;
return nullptr;
Expand Down Expand Up @@ -932,7 +932,7 @@ class TZEnumeration : public StringEnumeration {

TZEnumeration(const TZEnumeration &other) : StringEnumeration(), map(nullptr), localMap(nullptr), len(0), pos(0) {
if (other.localMap != nullptr) {
localMap = static_cast<int32_t*>(uprv_malloc(other.len * sizeof(int32_t)));
localMap = static_cast<int32_t*>(uprv_calloc(other.len, sizeof(int32_t)));
if (localMap != nullptr) {
len = other.len;
uprv_memcpy(localMap, other.localMap, len * sizeof(int32_t));
Expand Down