mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-11 08:01:32 +00:00
ICU-22962 Fix int32 overflow in Chinese Calendar
This commit is contained in:
parent
81d047524c
commit
a7291c4e51
3 changed files with 19 additions and 1 deletions
|
@ -1045,7 +1045,12 @@ void ChineseCalendar::offsetMonth(int32_t newMoon, int32_t dayOfMonth, int32_t d
|
|||
}
|
||||
|
||||
// Find the target dayOfMonth
|
||||
int32_t jd = newMoon + kEpochStartAsJulianDay - 1 + dayOfMonth;
|
||||
int32_t jd;
|
||||
if (uprv_add32_overflow(newMoon, kEpochStartAsJulianDay - 1, &jd) ||
|
||||
uprv_add32_overflow(jd, dayOfMonth, &jd)) {
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
// Pin the dayOfMonth. In this calendar all months are 29 or 30 days
|
||||
// so pinning just means handling dayOfMonth 30.
|
||||
|
|
|
@ -192,6 +192,7 @@ void CalendarTest::runIndexedTest( int32_t index, UBool exec, const char* &name,
|
|||
TESTCASE_AUTO(TestFirstDayOfWeek);
|
||||
|
||||
TESTCASE_AUTO(Test22633ChineseOverflow);
|
||||
TESTCASE_AUTO(Test22962ChineseOverflow);
|
||||
TESTCASE_AUTO(Test22633IndianOverflow);
|
||||
TESTCASE_AUTO(Test22633IslamicUmalquraOverflow);
|
||||
TESTCASE_AUTO(Test22633PersianOverflow);
|
||||
|
@ -5663,6 +5664,17 @@ void CalendarTest::Test22633ChineseOverflow() {
|
|||
cal->add(UCAL_YEAR, 1935762034, status);
|
||||
assertTrue("Should return falure", U_FAILURE(status));
|
||||
}
|
||||
|
||||
void CalendarTest::Test22962ChineseOverflow() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
LocalPointer<Calendar> cal(Calendar::createInstance(Locale("en@calendar=chinese"), status), status);
|
||||
U_ASSERT(U_SUCCESS(status));
|
||||
cal->add(UCAL_DAY_OF_WEEK_IN_MONTH, 1661092210, status);
|
||||
cal->add(UCAL_MINUTE, -1330638081, status);
|
||||
cal->add(UCAL_MONTH, 643194, status);
|
||||
assertTrue("Should return falure", U_FAILURE(status));
|
||||
}
|
||||
|
||||
void CalendarTest::Test22633IndianOverflow() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
LocalPointer<Calendar> cal(Calendar::createInstance(Locale("en@calendar=indian"), status), status);
|
||||
|
|
|
@ -335,6 +335,7 @@ public: // package
|
|||
void TestAddOverflow();
|
||||
void TestRollWeekOfYear();
|
||||
void Test22633ChineseOverflow();
|
||||
void Test22962ChineseOverflow();
|
||||
void Test22633IndianOverflow();
|
||||
void Test22633IslamicUmalquraOverflow();
|
||||
void Test22633PersianOverflow();
|
||||
|
|
Loading…
Add table
Reference in a new issue