ICU-9793 Fix segfault when from field not present in CurrencyMap.

X-SVN-Rev: 32960
This commit is contained in:
Jennifer Chye 2012-12-14 01:27:49 +00:00
parent 612181f2f5
commit 58fe813c16

View File

@ -1869,28 +1869,33 @@ ucurr_createCurrencyList(UErrorCode* status){
} }
const UChar *isoCode = ures_getString(idRes, &isoLength, &localStatus); const UChar *isoCode = ures_getString(idRes, &isoLength, &localStatus);
// get the from date // get from date
int32_t fromLength = 0; UDate fromDate = U_DATE_MIN;
UResourceBundle *fromRes = ures_getByKey(currencyRes, "from", NULL, &localStatus); UResourceBundle *fromRes = ures_getByKey(currencyRes, "from", NULL, &localStatus);
const int32_t *fromArray = ures_getIntVector(fromRes, &fromLength, &localStatus);
int64_t currDate64 = (int64_t)fromArray[0] << 32; if (U_SUCCESS(localStatus)) {
currDate64 |= ((int64_t)fromArray[1] & (int64_t)INT64_C(0x00000000FFFFFFFF)); int32_t fromLength = 0;
UDate fromDate = (UDate)currDate64; const int32_t *fromArray = ures_getIntVector(fromRes, &fromLength, &localStatus);
int64_t currDate64 = (int64_t)fromArray[0] << 32;
currDate64 |= ((int64_t)fromArray[1] & (int64_t)INT64_C(0x00000000FFFFFFFF));
fromDate = (UDate)currDate64;
}
ures_close(fromRes);
// get to date
UDate toDate = U_DATE_MAX; UDate toDate = U_DATE_MAX;
localStatus = U_ZERO_ERROR;
UResourceBundle *toRes = ures_getByKey(currencyRes, "to", NULL, &localStatus);
if (ures_getSize(currencyRes)> 2) { if (U_SUCCESS(localStatus)) {
int32_t toLength = 0; int32_t toLength = 0;
UResourceBundle *toRes = ures_getByKey(currencyRes, "to", NULL, &localStatus);
const int32_t *toArray = ures_getIntVector(toRes, &toLength, &localStatus); const int32_t *toArray = ures_getIntVector(toRes, &toLength, &localStatus);
int64_t currDate64 = (int64_t)toArray[0] << 32;
currDate64 = (int64_t)toArray[0] << 32;
currDate64 |= ((int64_t)toArray[1] & (int64_t)INT64_C(0x00000000FFFFFFFF)); currDate64 |= ((int64_t)toArray[1] & (int64_t)INT64_C(0x00000000FFFFFFFF));
toDate = (UDate)currDate64; toDate = (UDate)currDate64;
}
ures_close(toRes);
ures_close(toRes);
}
ures_close(fromRes);
ures_close(idRes); ures_close(idRes);
ures_close(currencyRes); ures_close(currencyRes);
@ -1898,6 +1903,7 @@ ucurr_createCurrencyList(UErrorCode* status){
entry->from = fromDate; entry->from = fromDate;
entry->to = toDate; entry->to = toDate;
localStatus = U_ZERO_ERROR;
uhash_put(gIsoCodes, (UChar *)isoCode, entry, &localStatus); uhash_put(gIsoCodes, (UChar *)isoCode, entry, &localStatus);
} }
} else { } else {
@ -1939,7 +1945,7 @@ ucurr_isAvailable(const UChar* isoCode, UDate from, UDate to, UErrorCode* eError
uhash_setValueDeleter(gIsoCodes, deleteIsoCodeEntry); uhash_setValueDeleter(gIsoCodes, deleteIsoCodeEntry);
ucln_i18n_registerCleanup(UCLN_I18N_CURRENCY, currency_cleanup); ucln_i18n_registerCleanup(UCLN_I18N_CURRENCY, currency_cleanup);
fprintf(stderr, "creating currency list");
ucurr_createCurrencyList(&status); ucurr_createCurrencyList(&status);
if (U_FAILURE(status)) { if (U_FAILURE(status)) {
umtx_unlock(&gIsoCodesLock); umtx_unlock(&gIsoCodesLock);