ICU-7295 ucal_open crash if locale==NULL && caltype==UCAL_GREGORIAN

X-SVN-Rev: 27414
This commit is contained in:
Peter Edberg 2010-01-26 07:21:21 +00:00
parent 54d51498c7
commit 4c6887c581
2 changed files with 11 additions and 4 deletions

View File

@ -135,6 +135,9 @@ ucal_open( const UChar* zoneID,
if ( caltype == UCAL_GREGORIAN ) {
char localeBuf[ULOC_LOCALE_IDENTIFIER_CAPACITY];
if ( locale == NULL ) {
locale = uloc_getDefault();
}
uprv_strncpy(localeBuf, locale, ULOC_LOCALE_IDENTIFIER_CAPACITY);
uloc_setKeywordValue("calendar", "gregorian", localeBuf, ULOC_LOCALE_IDENTIFIER_CAPACITY, status);
if (U_FAILURE(*status)) {

View File

@ -71,6 +71,9 @@ static const UCalGetTypeTest ucalGetTypeTests[] = {
{ "ja_JP@calendar=japanese", UCAL_DEFAULT, "japanese" },
{ "th_TH", UCAL_GREGORIAN, "gregorian" },
{ "th_TH", UCAL_DEFAULT, "buddhist" },
{ "ja_JP@calendar=japanese", UCAL_GREGORIAN, "gregorian" },
{ "", UCAL_GREGORIAN, "gregorian" },
{ NULL, UCAL_GREGORIAN, "gregorian" },
{ NULL, 0, NULL } /* terminator */
};
@ -415,22 +418,23 @@ static void TestCalendar()
ucal_close(calfrclone);
/*testing ucal_getType, and ucal_open with UCAL_GREGORIAN*/
for (ucalGetTypeTestPtr = ucalGetTypeTests; ucalGetTypeTestPtr->locale != NULL; ++ucalGetTypeTestPtr) {
for (ucalGetTypeTestPtr = ucalGetTypeTests; ucalGetTypeTestPtr->expectedResult != NULL; ++ucalGetTypeTestPtr) {
const char * localeToDisplay = (ucalGetTypeTestPtr->locale != NULL)? ucalGetTypeTestPtr->locale: "<NULL>";
status = U_ZERO_ERROR;
caldef = ucal_open(NULL, 0, ucalGetTypeTestPtr->locale, ucalGetTypeTestPtr->calType, &status);
if ( U_SUCCESS(status) ) {
const char * calType = ucal_getType(caldef, &status);
if ( U_SUCCESS(status) && calType != NULL ) {
if ( strcmp( calType, ucalGetTypeTestPtr->expectedResult ) != 0 ) {
log_err("FAIL: ucal_open %s type %d does not return %s calendar\n", ucalGetTypeTestPtr->locale,
log_err("FAIL: ucal_open %s type %d does not return %s calendar\n", localeToDisplay,
ucalGetTypeTestPtr->calType, ucalGetTypeTestPtr->expectedResult);
}
} else {
log_err("FAIL: ucal_open %s type %d, then ucal_getType fails\n", ucalGetTypeTestPtr->locale, ucalGetTypeTestPtr->calType);
log_err("FAIL: ucal_open %s type %d, then ucal_getType fails\n", localeToDisplay, ucalGetTypeTestPtr->calType);
}
ucal_close(caldef);
} else {
log_err("FAIL: ucal_open %s type %d fails\n", ucalGetTypeTestPtr->locale, ucalGetTypeTestPtr->calType);
log_err("FAIL: ucal_open %s type %d fails\n", localeToDisplay, ucalGetTypeTestPtr->calType);
}
}