Skip to content

Commit 06121a5

Browse files
committed
Fix compiler warnings
MSVC 14 complains about possible loss of data due to zend_long to int conversion in db_sdn_to_gregorian(). We fix that by constraining sdn to the required range (0001-01-01 .. 9999-12-31), showing that temp never exceeds int range (32bit for all supported architectures), and consequently declaring temp as int. git-svn-id: http://svn.php.net/repository/pecl/dbase/trunk@340808 c90b9560-bf6c-de11-be94-00142212c4b1
1 parent 44be0dc commit 06121a5

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

gregor.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,25 +133,24 @@ void db_sdn_to_gregorian(
133133
int year;
134134
int month;
135135
int day;
136-
zend_long temp;
136+
int temp;
137137
int dayOfYear;
138138

139-
if (sdn <= 0 ||
140-
sdn > (LONG_MAX - 4 * GREGOR_SDN_OFFSET) / 4) {
139+
if (sdn < 1721426 || sdn > 5373484) {
141140
goto fail;
142141
}
143-
temp = (sdn + GREGOR_SDN_OFFSET) * 4 - 1;
142+
temp = (int) ((sdn + GREGOR_SDN_OFFSET) * 4 - 1); // temp <= 0x149ED63
144143

145144
/* Calculate the century (year/100). */
146145
century = temp / DAYS_PER_400_YEARS;
147146

148147
/* Calculate the year and day of year (1 <= dayOfYear <= 366). */
149-
temp = ((temp % DAYS_PER_400_YEARS) / 4) * 4 + 3;
148+
temp = ((temp % DAYS_PER_400_YEARS) / 4) * 4 + 3; // temp <= 0x23AB3
150149
year = (century * 100) + (temp / DAYS_PER_4_YEARS);
151-
dayOfYear = (temp % DAYS_PER_4_YEARS) / 4 + 1;
150+
dayOfYear = (temp % DAYS_PER_4_YEARS) / 4 + 1; // dayOfYear = 0x16E
152151

153152
/* Calculate the month and day of month. */
154-
temp = dayOfYear * 5 - 3;
153+
temp = dayOfYear * 5 - 3; // temp <= 723
155154
month = temp / DAYS_PER_5_MONTHS;
156155
day = (temp % DAYS_PER_5_MONTHS) / 5 + 1;
157156

0 commit comments

Comments
 (0)