@@ -3968,24 +3968,22 @@ PHP_FUNCTION(date_diff)
39683968}
39693969/* }}} */
39703970
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 ) /* {{{ */
39723972{
39733973 timelib_time * dummy_t = ecalloc (1 , sizeof (timelib_time ));
39743974 int dst , not_found ;
3975- const char * orig_tz = tz ;
3975+ const char * tz = ZSTR_VAL ( tz_zstr ) ;
39763976
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" );
39813979 efree (dummy_t );
39823980 return false;
39833981 }
39843982
39853983 dummy_t -> z = timelib_parse_zone (& tz , & dst , dummy_t , & not_found , DATE_TIMEZONEDB , php_date_parse_tzfile_wrapper );
39863984 if ((dummy_t -> z >= (100 * 60 * 60 )) || (dummy_t -> z <= (-100 * 60 * 60 ))) {
39873985 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 ) );
39893987 }
39903988 timelib_free (dummy_t -> tz_abbr );
39913989 efree (dummy_t );
@@ -3994,15 +3992,15 @@ static bool timezone_initialize(php_timezone_obj *tzobj, const char *tz, size_t
39943992 dummy_t -> dst = dst ;
39953993 if (!not_found && (* tz != '\0' )) {
39963994 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 ) );
39983996 }
39993997 timelib_free (dummy_t -> tz_abbr );
40003998 efree (dummy_t );
40013999 return false;
40024000 }
40034001 if (not_found ) {
40044002 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 ) );
40064004 }
40074005 efree (dummy_t );
40084006 return false;
@@ -4026,7 +4024,7 @@ PHP_FUNCTION(timezone_open)
40264024 ZEND_PARSE_PARAMETERS_END ();
40274025
40284026 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 )) {
40304028 php_error_docref (NULL , E_WARNING , "%s" , warning_message );
40314029 efree (warning_message );
40324030 zval_ptr_dtor (return_value );
@@ -4047,7 +4045,7 @@ PHP_METHOD(DateTimeZone, __construct)
40474045 ZEND_PARSE_PARAMETERS_END ();
40484046
40494047 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 )) {
40514049 zend_throw_exception_ex (date_ce_date_invalid_timezone_exception , 0 , "DateTimeZone::__construct(): %s" , exception_message );
40524050 efree (exception_message );
40534051 RETURN_THROWS ();
@@ -4078,7 +4076,7 @@ static bool php_date_timezone_initialize_from_hash(zval **return_value, php_time
40784076 if (Z_TYPE_P (z_timezone ) != IS_STRING ) {
40794077 return false;
40804078 }
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 );
40824080} /* }}} */
40834081
40844082/* {{{ */
0 commit comments