mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
ICU-22750 Fix Floating-point-exception in icu::Calendar::roll
See #2979
This commit is contained in:
parent
0312308566
commit
a91cbd6578
3 changed files with 26 additions and 0 deletions
|
@ -1762,6 +1762,9 @@ void Calendar::roll(UCalendarDateFields field, int32_t amount, UErrorCode& statu
|
|||
{
|
||||
int32_t min = getActualMinimum(field,status);
|
||||
int32_t max = getActualMaximum(field,status);
|
||||
if (U_FAILURE(status)) {
|
||||
return;
|
||||
}
|
||||
int32_t gap = max - min + 1;
|
||||
|
||||
int64_t value = internalGet(field);
|
||||
|
|
|
@ -209,6 +209,7 @@ void CalendarTest::runIndexedTest( int32_t index, UBool exec, const char* &name,
|
|||
|
||||
TESTCASE_AUTO(TestAddOverflow);
|
||||
|
||||
TESTCASE_AUTO(Test22750Roll);
|
||||
|
||||
TESTCASE_AUTO(TestChineseCalendarComputeMonthStart);
|
||||
|
||||
|
@ -5929,6 +5930,25 @@ void CalendarTest::TestAddOverflow() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CalendarTest::Test22750Roll() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
Locale l(Locale::getRoot());
|
||||
std::unique_ptr<icu::StringEnumeration> enumeration(
|
||||
Calendar::getKeywordValuesForLocale("calendar", l, false, status));
|
||||
// Test every calendar
|
||||
for (const char* name = enumeration->next(nullptr, status);
|
||||
U_SUCCESS(status) && name != nullptr;
|
||||
name = enumeration->next(nullptr, status)) {
|
||||
UErrorCode status2 = U_ZERO_ERROR;
|
||||
l.setKeywordValue("calendar", name, status2);
|
||||
LocalPointer<Calendar> calendar(Calendar::createInstance(l, status2));
|
||||
if (failure(status2, "Calendar::createInstance")) return;
|
||||
calendar->add(UCAL_DAY_OF_WEEK_IN_MONTH, 538976288, status2);
|
||||
calendar->roll(UCAL_DATE, 538976288, status2);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
//eof
|
||||
|
|
|
@ -347,6 +347,9 @@ public: // package
|
|||
void Test22633AddTwiceGetTimeOverflow();
|
||||
void Test22633RollTwiceGetTimeOverflow();
|
||||
void Test22730JapaneseOverflow();
|
||||
|
||||
void Test22750Roll();
|
||||
|
||||
void RunTestOnCalendars(void(TestFunc)(Calendar*, UCalendarDateFields));
|
||||
|
||||
void verifyFirstDayOfWeek(const char* locale, UCalendarDaysOfWeek expected);
|
||||
|
|
Loading…
Add table
Reference in a new issue