Skip to content

Commit 548fe60

Browse files
committed
Added PHP_DATE_DOUBLE_FITS_LONG similar to ZEND_DOUBLE_FITS_LONG
1 parent 1781833 commit 548fe60

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

ext/date/php_date.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,8 +2517,7 @@ PHPAPI bool php_date_initialize_from_ts_double(php_date_obj *dateobj, double ts)
25172517
int usec = (int)(fmod(ts, 1) * 1000000);
25182518

25192519
if (UNEXPECTED(isnan(sec_dval)
2520-
|| sec_dval > (double)TIMELIB_LONG_MAX
2521-
|| sec_dval < (double)TIMELIB_LONG_MIN
2520+
|| !PHP_DATE_DOUBLE_FITS_LONG(sec_dval)
25222521
|| (sec == TIMELIB_LONG_MIN && usec < 0)
25232522
)) {
25242523
zend_throw_error(

ext/date/php_date.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
#include "lib/timelib.h"
2121
#include "Zend/zend_hash.h"
2222

23+
/* Same as ZEND_DOUBLE_FITS_LONG but using TIMELIB_LONG_MAX/MIN */
24+
#if SIZEOF_TIMELIB_LONG == 4
25+
# define PHP_DATE_DOUBLE_FITS_LONG(d) (!((d) > (double)TIMELIB_LONG_MAX || (d) < (double)TIMELIB_LONG_MIN))
26+
#else
27+
/* >= as (double)TIMELIB_LONG_MAX is outside signed range */
28+
# define PHP_DATE_DOUBLE_FITS_LONG(d) (!((d) >= (double)TIMELIB_LONG_MAX || (d) < (double)TIMELIB_LONG_MIN))
29+
#endif
30+
2331
#include "php_version.h"
2432
#define PHP_DATE_VERSION PHP_VERSION
2533

0 commit comments

Comments
 (0)