Skip to content

Commit dae83f8

Browse files
committed
Add warnings for when Epoch doesn't fit in a PHP integer
1 parent 16757ca commit dae83f8

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

ext/date/php_date.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ PHPAPI zend_long php_parse_date(const char *string, zend_long *now)
10091009
PHP_FUNCTION(strtotime)
10101010
{
10111011
zend_string *times;
1012-
int error1, error2;
1012+
int error1, epoch_does_not_fit_in_zend_long;
10131013
timelib_error_container *error;
10141014
zend_long preset_ts, ts;
10151015
zend_bool preset_ts_is_null = 1;
@@ -1024,7 +1024,6 @@ PHP_FUNCTION(strtotime)
10241024

10251025
/* timelib_strtotime() expects the string to not be empty */
10261026
if (ZSTR_LEN(times) == 0) {
1027-
/* TODO Add a Warning? */
10281027
RETURN_FALSE;
10291028
}
10301029

@@ -1048,14 +1047,14 @@ PHP_FUNCTION(strtotime)
10481047

10491048
timelib_fill_holes(t, now, TIMELIB_NO_CLONE);
10501049
timelib_update_ts(t, tzi);
1051-
ts = timelib_date_to_int(t, &error2);
1050+
ts = timelib_date_to_int(t, &epoch_does_not_fit_in_zend_long);
10521051

10531052
timelib_time_dtor(now);
10541053
timelib_time_dtor(t);
10551054

10561055
/* Seconds since epoch must fit in a zend_long */
1057-
if (error2) {
1058-
/* TODO Add warning? */
1056+
if (epoch_does_not_fit_in_zend_long) {
1057+
php_error_docref(NULL, E_WARNING, "Epoch doesn't fit in a PHP integer");
10591058
RETURN_FALSE;
10601059
}
10611060

@@ -1071,7 +1070,7 @@ PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
10711070
timelib_time *now;
10721071
timelib_tzinfo *tzi = NULL;
10731072
zend_long ts, adjust_seconds = 0;
1074-
int error;
1073+
int epoch_does_not_fit_in_zend_long;
10751074

10761075
ZEND_PARSE_PARAMETERS_START(1, 6)
10771076
Z_PARAM_LONG(hou)
@@ -1129,12 +1128,12 @@ PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
11291128
}
11301129

11311130
/* Clean up and return */
1132-
ts = timelib_date_to_int(now, &error);
1131+
ts = timelib_date_to_int(now, &epoch_does_not_fit_in_zend_long);
11331132

11341133
/* Seconds since epoch must fit in a zend_long */
1135-
if (error) {
1134+
if (epoch_does_not_fit_in_zend_long) {
11361135
timelib_time_dtor(now);
1137-
/* TODO Add warning? */
1136+
php_error_docref(NULL, E_WARNING, "Epoch doesn't fit in a PHP integer");
11381137
RETURN_FALSE;
11391138
}
11401139

@@ -1198,7 +1197,6 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
11981197
ZEND_PARSE_PARAMETERS_END();
11991198

12001199
if (ZSTR_LEN(format) == 0) {
1201-
/* TODO Add a warning? */
12021200
RETURN_FALSE;
12031201
}
12041202

@@ -3328,7 +3326,7 @@ PHP_FUNCTION(date_timestamp_get)
33283326
zval *object;
33293327
php_date_obj *dateobj;
33303328
zend_long timestamp;
3331-
int error;
3329+
int epoch_does_not_fit_in_zend_long;
33323330

33333331
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &object, date_ce_interface) == FAILURE) {
33343332
RETURN_THROWS();
@@ -3337,11 +3335,11 @@ PHP_FUNCTION(date_timestamp_get)
33373335
DATE_CHECK_INITIALIZED(dateobj->time, DateTime);
33383336
timelib_update_ts(dateobj->time, NULL);
33393337

3340-
timestamp = timelib_date_to_int(dateobj->time, &error);
3338+
timestamp = timelib_date_to_int(dateobj->time, &epoch_does_not_fit_in_zend_long);
33413339

33423340
/* Seconds since epoch must fit in a zend_long */
3343-
if (error) {
3344-
/* TODO Add warning? */
3341+
if (epoch_does_not_fit_in_zend_long) {
3342+
php_error_docref(NULL, E_WARNING, "Epoch doesn't fit in a PHP integer");
33453343
RETURN_FALSE;
33463344
}
33473345

0 commit comments

Comments
 (0)