mirror of
https://github.com/php/php-src.git
synced 2025-08-15 13:38:49 +02:00
Use stack allocation in timezone_initialize() (#19394)
This lives temporarily, avoid overhead and handling of heap allocation.
This commit is contained in:
parent
9673079903
commit
99e6b0ecc8
1 changed files with 8 additions and 12 deletions
|
@ -3970,40 +3970,36 @@ PHP_FUNCTION(date_diff)
|
||||||
|
|
||||||
static bool timezone_initialize(php_timezone_obj *tzobj, const zend_string *tz_zstr, char **warning_message) /* {{{ */
|
static bool timezone_initialize(php_timezone_obj *tzobj, const zend_string *tz_zstr, char **warning_message) /* {{{ */
|
||||||
{
|
{
|
||||||
timelib_time *dummy_t = ecalloc(1, sizeof(timelib_time));
|
timelib_time dummy_t = {0};
|
||||||
int dst, not_found;
|
int dst, not_found;
|
||||||
const char *tz = ZSTR_VAL(tz_zstr);
|
const char *tz = ZSTR_VAL(tz_zstr);
|
||||||
|
|
||||||
ZEND_ASSERT(!zend_str_has_nul_byte(tz_zstr) && "timezone should have been checked to not have null bytes");
|
ZEND_ASSERT(!zend_str_has_nul_byte(tz_zstr) && "timezone should have been checked to not have null bytes");
|
||||||
|
|
||||||
dummy_t->z = timelib_parse_zone(&tz, &dst, dummy_t, ¬_found, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
|
dummy_t.z = timelib_parse_zone(&tz, &dst, &dummy_t, ¬_found, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
|
||||||
if ((dummy_t->z >= (100 * 60 * 60)) || (dummy_t->z <= (-100 * 60 * 60))) {
|
if ((dummy_t.z >= (100 * 60 * 60)) || (dummy_t.z <= (-100 * 60 * 60))) {
|
||||||
if (warning_message) {
|
if (warning_message) {
|
||||||
spprintf(warning_message, 0, "Timezone offset is out of range (%s)", ZSTR_VAL(tz_zstr));
|
spprintf(warning_message, 0, "Timezone offset is out of range (%s)", ZSTR_VAL(tz_zstr));
|
||||||
}
|
}
|
||||||
timelib_free(dummy_t->tz_abbr);
|
timelib_free(dummy_t.tz_abbr);
|
||||||
efree(dummy_t);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
dummy_t->dst = dst;
|
dummy_t.dst = dst;
|
||||||
if (!not_found && (*tz != '\0')) {
|
if (!not_found && (*tz != '\0')) {
|
||||||
if (warning_message) {
|
if (warning_message) {
|
||||||
spprintf(warning_message, 0, "Unknown or bad timezone (%s)", ZSTR_VAL(tz_zstr));
|
spprintf(warning_message, 0, "Unknown or bad timezone (%s)", ZSTR_VAL(tz_zstr));
|
||||||
}
|
}
|
||||||
timelib_free(dummy_t->tz_abbr);
|
timelib_free(dummy_t.tz_abbr);
|
||||||
efree(dummy_t);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (not_found) {
|
if (not_found) {
|
||||||
if (warning_message) {
|
if (warning_message) {
|
||||||
spprintf(warning_message, 0, "Unknown or bad timezone (%s)", ZSTR_VAL(tz_zstr));
|
spprintf(warning_message, 0, "Unknown or bad timezone (%s)", ZSTR_VAL(tz_zstr));
|
||||||
}
|
}
|
||||||
efree(dummy_t);
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
set_timezone_from_timelib_time(tzobj, dummy_t);
|
set_timezone_from_timelib_time(tzobj, &dummy_t);
|
||||||
timelib_free(dummy_t->tz_abbr);
|
timelib_free(dummy_t.tz_abbr);
|
||||||
efree(dummy_t);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue