Skip to content

Commit 39dcc1d

Browse files

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

ext/calendar/gregor.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,29 +144,24 @@ void SdnToGregorian(
144144
int year;
145145
int month;
146146
int day;
147-
zend_long temp;
147+
int temp;
148148
int dayOfYear;
149149

150-
if (sdn <= 0 ||
151-
sdn > (LONG_MAX - 4 * GREGOR_SDN_OFFSET) / 4) {
152-
goto fail;
153-
}
154-
temp = (sdn + GREGOR_SDN_OFFSET) * 4 - 1;
155-
156-
if (temp < 0 || (temp / DAYS_PER_400_YEARS) > INT_MAX) {
150+
if (sdn < 1721426 || sdn >5373484) {
157151
goto fail;
158152
}
153+
temp = (int)(sdn + GREGOR_SDN_OFFSET) * 4 - 1; // temp <= 0x149ED63
159154

160155
/* Calculate the century (year/100). */
161156
century = temp / DAYS_PER_400_YEARS;
162157

163158
/* Calculate the year and day of year (1 <= dayOfYear <= 366). */
164-
temp = ((temp % DAYS_PER_400_YEARS) / 4) * 4 + 3;
159+
temp = ((temp % DAYS_PER_400_YEARS) / 4) * 4 + 3; // temp <= 0x23AB3
165160
year = (century * 100) + (temp / DAYS_PER_4_YEARS);
166-
dayOfYear = (temp % DAYS_PER_4_YEARS) / 4 + 1;
161+
dayOfYear = (temp % DAYS_PER_4_YEARS) / 4 + 1; // dayOfYear = 0x16E
167162

168163
/* Calculate the month and day of month. */
169-
temp = dayOfYear * 5 - 3;
164+
temp = dayOfYear * 5 - 3; // temp <= 723
170165
month = temp / DAYS_PER_5_MONTHS;
171166
day = (temp % DAYS_PER_5_MONTHS) / 5 + 1;
172167

0 commit comments

Comments
 (0)