Skip to content

Commit 491db8b

Browse files
committed
Make ASAN happy
1 parent 548fe60 commit 491db8b

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

ext/date/php_date.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,13 +2513,10 @@ PHPAPI void php_date_initialize_from_ts_long(php_date_obj *dateobj, zend_long se
25132513
PHPAPI bool php_date_initialize_from_ts_double(php_date_obj *dateobj, double ts) /* {{{ */
25142514
{
25152515
double sec_dval = trunc(ts);
2516-
zend_long sec = (zend_long)sec_dval;
2517-
int usec = (int)(fmod(ts, 1) * 1000000);
2516+
zend_long sec;
2517+
int usec;
25182518

2519-
if (UNEXPECTED(isnan(sec_dval)
2520-
|| !PHP_DATE_DOUBLE_FITS_LONG(sec_dval)
2521-
|| (sec == TIMELIB_LONG_MIN && usec < 0)
2522-
)) {
2519+
if (UNEXPECTED(isnan(sec_dval) || !PHP_DATE_DOUBLE_FITS_LONG(sec_dval))) {
25232520
zend_throw_error(
25242521
date_ce_date_range_error,
25252522
"Seconds must be a finite number between " TIMELIB_LONG_FMT " and " TIMELIB_LONG_FMT ", %g given",
@@ -2530,7 +2527,21 @@ PHPAPI bool php_date_initialize_from_ts_double(php_date_obj *dateobj, double ts)
25302527
return false;
25312528
}
25322529

2530+
sec = (zend_long)sec_dval;
2531+
usec = (int)(fmod(ts, 1) * 1000000);
2532+
25332533
if (UNEXPECTED(usec < 0)) {
2534+
if (UNEXPECTED(sec == TIMELIB_LONG_MIN)) {
2535+
zend_throw_error(
2536+
date_ce_date_range_error,
2537+
"Seconds must be a finite number between " TIMELIB_LONG_FMT " and " TIMELIB_LONG_FMT ", %g given",
2538+
TIMELIB_LONG_MIN,
2539+
TIMELIB_LONG_MAX,
2540+
sec_dval
2541+
);
2542+
return false;
2543+
}
2544+
25342545
sec = sec - 1;
25352546
usec = 1000000 + usec;
25362547
}

0 commit comments

Comments
 (0)