ICU-21035 Replace backward compatibility ulocimp_getCountry() overload.

By always calling the dynamic memory allocation implementation directly
instead, the fixed memory buffer boundary gets pushed one step further
towards the edges.
This commit is contained in:
Fredrik Roubert 2020-08-21 00:16:23 +02:00 committed by Fredrik Roubert
parent db3278a71e
commit e8f3d5c657
3 changed files with 15 additions and 20 deletions

View File

@ -509,8 +509,7 @@ parseTagString(
} }
} }
subtagLength = ulocimp_getCountry(position, region, *regionLength, &position); subtagLength = ulocimp_getCountry(position, &position, *err).extract(region, *regionLength, *err);
u_terminateChars(region, *regionLength, subtagLength, err);
if(U_FAILURE(*err)) { if(U_FAILURE(*err)) {
goto error; goto error;

View File

@ -1215,7 +1215,7 @@ ulocimp_getScript(const char *localeID,
return result; return result;
} }
static CharString CharString U_EXPORT2
ulocimp_getCountry(const char *localeID, ulocimp_getCountry(const char *localeID,
const char **pEnd, const char **pEnd,
UErrorCode &status) { UErrorCode &status) {
@ -1250,14 +1250,6 @@ ulocimp_getCountry(const char *localeID,
return result; return result;
} }
U_CFUNC int32_t
ulocimp_getCountry(const char *localeID,
char *country, int32_t countryCapacity,
const char **pEnd) {
ErrorCode status;
return ulocimp_getCountry(localeID, pEnd, status).extract(country, countryCapacity, status);
}
/** /**
* @param needSeparator if true, then add leading '_' if any variants * @param needSeparator if true, then add leading '_' if any variants
* are added to 'variant' * are added to 'variant'
@ -1458,7 +1450,10 @@ uloc_openKeywords(const char* localeID,
} }
/* Skip the Country */ /* Skip the Country */
if (_isIDSeparator(*tmpLocaleID)) { if (_isIDSeparator(*tmpLocaleID)) {
ulocimp_getCountry(tmpLocaleID+1, NULL, 0, &tmpLocaleID); ulocimp_getCountry(tmpLocaleID+1, &tmpLocaleID, *status);
if (U_FAILURE(*status)) {
return 0;
}
if(_isIDSeparator(*tmpLocaleID)) { if(_isIDSeparator(*tmpLocaleID)) {
_getVariant(tmpLocaleID+1, *tmpLocaleID, NULL, 0); _getVariant(tmpLocaleID+1, *tmpLocaleID, NULL, 0);
} }
@ -1750,8 +1745,6 @@ uloc_getCountry(const char* localeID,
int32_t countryCapacity, int32_t countryCapacity,
UErrorCode* err) UErrorCode* err)
{ {
int32_t i=0;
if(err==NULL || U_FAILURE(*err)) { if(err==NULL || U_FAILURE(*err)) {
return 0; return 0;
} }
@ -1778,10 +1771,10 @@ uloc_getCountry(const char* localeID,
localeID = scriptID; localeID = scriptID;
} }
if(_isIDSeparator(*localeID)) { if(_isIDSeparator(*localeID)) {
i=ulocimp_getCountry(localeID+1, country, countryCapacity, NULL); return ulocimp_getCountry(localeID+1, NULL, *err).extract(country, countryCapacity, *err);
} }
} }
return u_terminateChars(country, countryCapacity, i, err); return u_terminateChars(country, countryCapacity, 0, err);
} }
U_CAPI int32_t U_EXPORT2 U_CAPI int32_t U_EXPORT2
@ -1827,7 +1820,10 @@ uloc_getVariant(const char* localeID,
/* Skip the Country */ /* Skip the Country */
if (_isIDSeparator(*tmpLocaleID)) { if (_isIDSeparator(*tmpLocaleID)) {
const char *cntryID; const char *cntryID;
ulocimp_getCountry(tmpLocaleID+1, NULL, 0, &cntryID); ulocimp_getCountry(tmpLocaleID+1, &cntryID, *err);
if (U_FAILURE(*err)) {
return 0;
}
if (cntryID != tmpLocaleID+1) { if (cntryID != tmpLocaleID+1) {
/* Found optional country */ /* Found optional country */
tmpLocaleID = cntryID; tmpLocaleID = cntryID;

View File

@ -59,10 +59,10 @@ ulocimp_getScript(const char *localeID,
const char **pEnd, const char **pEnd,
UErrorCode &status); UErrorCode &status);
U_CFUNC int32_t icu::CharString U_EXPORT2
ulocimp_getCountry(const char *localeID, ulocimp_getCountry(const char *localeID,
char *country, int32_t countryCapacity, const char **pEnd,
const char **pEnd); UErrorCode &status);
U_STABLE void U_EXPORT2 U_STABLE void U_EXPORT2
ulocimp_getName(const char* localeID, ulocimp_getName(const char* localeID,