@@ -3968,24 +3968,22 @@ PHP_FUNCTION(date_diff)
3968
3968
}
3969
3969
/* }}} */
3970
3970
3971
- static bool timezone_initialize (php_timezone_obj * tzobj , const char * tz , size_t tz_len , char * * warning_message ) /* {{{ */
3971
+ static bool timezone_initialize (php_timezone_obj * tzobj , const zend_string * tz_zstr , char * * warning_message ) /* {{{ */
3972
3972
{
3973
3973
timelib_time * dummy_t = ecalloc (1 , sizeof (timelib_time ));
3974
3974
int dst , not_found ;
3975
- const char * orig_tz = tz ;
3975
+ const char * tz = ZSTR_VAL ( tz_zstr ) ;
3976
3976
3977
- if (strlen (tz ) != tz_len ) {
3978
- if (warning_message ) {
3979
- spprintf (warning_message , 0 , "Timezone must not contain null bytes" );
3980
- }
3977
+ if (UNEXPECTED (zend_str_has_nul_byte (tz_zstr ))) {
3978
+ ZEND_ASSERT (warning_message == NULL && "Should only be possible if initialized via a HashTable" );
3981
3979
efree (dummy_t );
3982
3980
return false;
3983
3981
}
3984
3982
3985
3983
dummy_t -> z = timelib_parse_zone (& tz , & dst , dummy_t , & not_found , DATE_TIMEZONEDB , php_date_parse_tzfile_wrapper );
3986
3984
if ((dummy_t -> z >= (100 * 60 * 60 )) || (dummy_t -> z <= (-100 * 60 * 60 ))) {
3987
3985
if (warning_message ) {
3988
- spprintf (warning_message , 0 , "Timezone offset is out of range (%s)" , orig_tz );
3986
+ spprintf (warning_message , 0 , "Timezone offset is out of range (%s)" , ZSTR_VAL ( tz_zstr ) );
3989
3987
}
3990
3988
timelib_free (dummy_t -> tz_abbr );
3991
3989
efree (dummy_t );
@@ -3994,15 +3992,15 @@ static bool timezone_initialize(php_timezone_obj *tzobj, const char *tz, size_t
3994
3992
dummy_t -> dst = dst ;
3995
3993
if (!not_found && (* tz != '\0' )) {
3996
3994
if (warning_message ) {
3997
- spprintf (warning_message , 0 , "Unknown or bad timezone (%s)" , orig_tz );
3995
+ spprintf (warning_message , 0 , "Unknown or bad timezone (%s)" , ZSTR_VAL ( tz_zstr ) );
3998
3996
}
3999
3997
timelib_free (dummy_t -> tz_abbr );
4000
3998
efree (dummy_t );
4001
3999
return false;
4002
4000
}
4003
4001
if (not_found ) {
4004
4002
if (warning_message ) {
4005
- spprintf (warning_message , 0 , "Unknown or bad timezone (%s)" , orig_tz );
4003
+ spprintf (warning_message , 0 , "Unknown or bad timezone (%s)" , ZSTR_VAL ( tz_zstr ) );
4006
4004
}
4007
4005
efree (dummy_t );
4008
4006
return false;
@@ -4026,7 +4024,7 @@ PHP_FUNCTION(timezone_open)
4026
4024
ZEND_PARSE_PARAMETERS_END ();
4027
4025
4028
4026
tzobj = Z_PHPTIMEZONE_P (php_date_instantiate (date_ce_timezone , return_value ));
4029
- if (!timezone_initialize (tzobj , ZSTR_VAL ( tz ), ZSTR_LEN ( tz ) , & warning_message )) {
4027
+ if (!timezone_initialize (tzobj , tz , & warning_message )) {
4030
4028
php_error_docref (NULL , E_WARNING , "%s" , warning_message );
4031
4029
efree (warning_message );
4032
4030
zval_ptr_dtor (return_value );
@@ -4047,7 +4045,7 @@ PHP_METHOD(DateTimeZone, __construct)
4047
4045
ZEND_PARSE_PARAMETERS_END ();
4048
4046
4049
4047
tzobj = Z_PHPTIMEZONE_P (ZEND_THIS );
4050
- if (!timezone_initialize (tzobj , ZSTR_VAL ( tz ), ZSTR_LEN ( tz ) , & exception_message )) {
4048
+ if (!timezone_initialize (tzobj , tz , & exception_message )) {
4051
4049
zend_throw_exception_ex (date_ce_date_invalid_timezone_exception , 0 , "DateTimeZone::__construct(): %s" , exception_message );
4052
4050
efree (exception_message );
4053
4051
RETURN_THROWS ();
@@ -4078,7 +4076,7 @@ static bool php_date_timezone_initialize_from_hash(zval **return_value, php_time
4078
4076
if (Z_TYPE_P (z_timezone ) != IS_STRING ) {
4079
4077
return false;
4080
4078
}
4081
- return timezone_initialize (* tzobj , Z_STRVAL_P ( z_timezone ), Z_STRLEN_P (z_timezone ), NULL );
4079
+ return timezone_initialize (* tzobj , Z_STR_P (z_timezone ), NULL );
4082
4080
} /* }}} */
4083
4081
4084
4082
/* {{{ */
0 commit comments