]> granicus.if.org Git - icu/commitdiff
ICU-20079 int overflow in Gregorian Calendar. (#66)
authorAndy Heninger <andy.heninger@gmail.com>
Fri, 24 Aug 2018 17:50:56 +0000 (10:50 -0700)
committerShane Carr <shane@unicode.org>
Thu, 27 Sep 2018 21:27:38 +0000 (14:27 -0700)
icu4c/source/i18n/gregocal.cpp
icu4c/source/i18n/gregoimp.h

index 0485cca7cd935d0a02e2ea6bcca6cd52d6fdd956..a4a464626a8690ae3a2ef9b762a5deff692b3bf4 100644 (file)
@@ -541,8 +541,8 @@ int32_t GregorianCalendar::handleComputeMonthStart(int32_t eyear, int32_t month,
     }
 
     UBool isLeap = eyear%4 == 0;
-    int32_t y = eyear-1;
-    int32_t julianDay = 365*y + ClockMath::floorDivide(y, 4) + (kJan1_1JulianDay - 3);
+    int64_t y = (int64_t)eyear-1;
+    int64_t julianDay = 365*y + ClockMath::floorDivide(y, (int64_t)4) + (kJan1_1JulianDay - 3);
 
     nonConstThis->fIsGregorian = (eyear >= fGregorianCutoverYear);
 #if defined (U_DEBUG_CAL)
index afaacda0b41a74426ac0acb18ab8a018f54eea9d..4fd868f4150aafb45b3bfd5244ce3571422604d6 100644 (file)
@@ -299,8 +299,8 @@ inline int32_t Grego::millisToJulianDay(double millis) {
 }
 
 inline int32_t Grego::gregorianShift(int32_t eyear) {
-  int32_t y = eyear-1;
-  int32_t gregShift = ClockMath::floorDivide(y, 400) - ClockMath::floorDivide(y, 100) + 2;
+  int64_t y = (int64_t)eyear-1;
+  int32_t gregShift = ClockMath::floorDivide(y, (int64_t)400) - ClockMath::floorDivide(y, (int64_t)100) + 2;
   return gregShift;
 }