From 1c360497c709f8e5fd1aa877b5bf0c8b7ee04505 Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Thu, 1 Mar 2012 23:50:07 +0000 Subject: [PATCH] ICU-9139 UCONFIG_NO_CONVERSION=1 bug fix X-SVN-Rev: 31561 --- icu4c/source/i18n/dtitvinf.cpp | 20 ++++++++++---------- icu4c/source/i18n/dtptngen.cpp | 10 +++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/icu4c/source/i18n/dtitvinf.cpp b/icu4c/source/i18n/dtitvinf.cpp index 8d339f4da3..65be28469b 100644 --- a/icu4c/source/i18n/dtitvinf.cpp +++ b/icu4c/source/i18n/dtitvinf.cpp @@ -221,7 +221,6 @@ DateIntervalInfo::initializeData(const Locale& locale, UErrorCode& err) } const char *locName = locale.getName(); char parentLocale[ULOC_FULLNAME_CAPACITY]; - int32_t locNameLen; uprv_strcpy(parentLocale, locName); UErrorCode status = U_ZERO_ERROR; Hashtable skeletonSet(FALSE, status); @@ -335,19 +334,20 @@ DateIntervalInfo::initializeData(const Locale& locale, UErrorCode& err) // Find the name of the appropriate parent locale (from %%Parent if present, else // uloc_getParent on the actual locale name) // (It would be nice to have a ures function that did this...) + int32_t locNameLen; const UChar * parentUName = ures_getStringByKey(rb, "%%Parent", &locNameLen, &status); - if (U_SUCCESS(status) && status != U_USING_FALLBACK_WARNING) { - u_austrncpy(parentLocale, parentUName, ULOC_FULLNAME_CAPACITY); // Should work on EBCDIC too? + if (U_SUCCESS(status) && status != U_USING_FALLBACK_WARNING && locNameLen < ULOC_FULLNAME_CAPACITY) { + u_UCharsToChars(parentUName, parentLocale, locNameLen + 1); } else { status = U_ZERO_ERROR; - // Get the actual name of the current locale being used - const char *curLocaleName=ures_getLocaleByType(rb, ULOC_ACTUAL_LOCALE, &status); - if ( U_FAILURE(status) ) { - curLocaleName = parentLocale; - status = U_ZERO_ERROR; - } - locNameLen = uloc_getParent(curLocaleName, parentLocale, ULOC_FULLNAME_CAPACITY, &status); + // Get the actual name of the current locale being used + const char *curLocaleName=ures_getLocaleByType(rb, ULOC_ACTUAL_LOCALE, &status); if ( U_FAILURE(status) ) { + curLocaleName = parentLocale; + status = U_ZERO_ERROR; + } + uloc_getParent(curLocaleName, parentLocale, ULOC_FULLNAME_CAPACITY, &status); + if (U_FAILURE(err) || err == U_STRING_NOT_TERMINATED_WARNING) { parentLocale[0] = 0; // just fallback to root, will cause us to stop status = U_ZERO_ERROR; } diff --git a/icu4c/source/i18n/dtptngen.cpp b/icu4c/source/i18n/dtptngen.cpp index 136e3e8061..b4e39b5087 100644 --- a/icu4c/source/i18n/dtptngen.cpp +++ b/icu4c/source/i18n/dtptngen.cpp @@ -608,7 +608,6 @@ DateTimePatternGenerator::addCLDRData(const Locale& locale, UErrorCode& err) { // add available formats UBool firstTimeThrough = TRUE; - char parentLocale[ULOC_FULLNAME_CAPACITY]; err = U_ZERO_ERROR; initHashtable(err); while (TRUE) { @@ -663,14 +662,15 @@ DateTimePatternGenerator::addCLDRData(const Locale& locale, UErrorCode& err) { // uloc_getParent on the actual locale name) // (It would be nice to have a ures function that did this...) err = U_ZERO_ERROR; + char parentLocale[ULOC_FULLNAME_CAPACITY]; int32_t locNameLen; const UChar * parentUName = ures_getStringByKey(rb, "%%Parent", &locNameLen, &err); - if (U_SUCCESS(err) && err != U_USING_FALLBACK_WARNING) { - u_austrncpy(parentLocale, parentUName, ULOC_FULLNAME_CAPACITY); // Should work on EBCDIC too? + if (U_SUCCESS(err) && err != U_USING_FALLBACK_WARNING && locNameLen < ULOC_FULLNAME_CAPACITY) { + u_UCharsToChars(parentUName, parentLocale, locNameLen + 1); } else { err = U_ZERO_ERROR; - locNameLen = uloc_getParent(curLocaleName, parentLocale, ULOC_FULLNAME_CAPACITY, &err); - if ( U_FAILURE(err) ) { + uloc_getParent(curLocaleName, parentLocale, ULOC_FULLNAME_CAPACITY, &err); + if (U_FAILURE(err) || err == U_STRING_NOT_TERMINATED_WARNING) { // just fallback to root, since we are not already there parentLocale[0] = 0; err = U_ZERO_ERROR;