Skip to content

Commit 99e6b0e

Browse files
authored
Use stack allocation in timezone_initialize() (#19394)
This lives temporarily, avoid overhead and handling of heap allocation.
1 parent 9673079 commit 99e6b0e

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

ext/date/php_date.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3970,40 +3970,36 @@ PHP_FUNCTION(date_diff)
39703970

39713971
static bool timezone_initialize(php_timezone_obj *tzobj, const zend_string *tz_zstr, char **warning_message) /* {{{ */
39723972
{
3973-
timelib_time *dummy_t = ecalloc(1, sizeof(timelib_time));
3973+
timelib_time dummy_t = {0};
39743974
int dst, not_found;
39753975
const char *tz = ZSTR_VAL(tz_zstr);
39763976

39773977
ZEND_ASSERT(!zend_str_has_nul_byte(tz_zstr) && "timezone should have been checked to not have null bytes");
39783978

3979-
dummy_t->z = timelib_parse_zone(&tz, &dst, dummy_t, &not_found, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
3980-
if ((dummy_t->z >= (100 * 60 * 60)) || (dummy_t->z <= (-100 * 60 * 60))) {
3979+
dummy_t.z = timelib_parse_zone(&tz, &dst, &dummy_t, &not_found, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
3980+
if ((dummy_t.z >= (100 * 60 * 60)) || (dummy_t.z <= (-100 * 60 * 60))) {
39813981
if (warning_message) {
39823982
spprintf(warning_message, 0, "Timezone offset is out of range (%s)", ZSTR_VAL(tz_zstr));
39833983
}
3984-
timelib_free(dummy_t->tz_abbr);
3985-
efree(dummy_t);
3984+
timelib_free(dummy_t.tz_abbr);
39863985
return false;
39873986
}
3988-
dummy_t->dst = dst;
3987+
dummy_t.dst = dst;
39893988
if (!not_found && (*tz != '\0')) {
39903989
if (warning_message) {
39913990
spprintf(warning_message, 0, "Unknown or bad timezone (%s)", ZSTR_VAL(tz_zstr));
39923991
}
3993-
timelib_free(dummy_t->tz_abbr);
3994-
efree(dummy_t);
3992+
timelib_free(dummy_t.tz_abbr);
39953993
return false;
39963994
}
39973995
if (not_found) {
39983996
if (warning_message) {
39993997
spprintf(warning_message, 0, "Unknown or bad timezone (%s)", ZSTR_VAL(tz_zstr));
40003998
}
4001-
efree(dummy_t);
40023999
return false;
40034000
} else {
4004-
set_timezone_from_timelib_time(tzobj, dummy_t);
4005-
timelib_free(dummy_t->tz_abbr);
4006-
efree(dummy_t);
4001+
set_timezone_from_timelib_time(tzobj, &dummy_t);
4002+
timelib_free(dummy_t.tz_abbr);
40074003
return true;
40084004
}
40094005
} /* }}} */

0 commit comments

Comments
 (0)