@@ -43,16 +43,16 @@ static void internal_parse_to_timestamp(IntlDateFormatter_object *dfo, char* tex
43
43
INTL_METHOD_CHECK_STATUS (dfo , "Error converting timezone to UTF-16" );
44
44
45
45
if (UNEXPECTED (update_calendar )) {
46
- UCalendar * parsed_calendar = (UCalendar * )udat_getCalendar (DATE_FORMAT_OBJECT (dfo ));
47
- udat_parseCalendar ( DATE_FORMAT_OBJECT (dfo ), parsed_calendar , text_utf16 , text_utf16_len , parse_pos , & INTL_DATA_ERROR_CODE (dfo ));
48
- if ( text_utf16 ) {
46
+ UCalendar * parsed_calendar = (UCalendar * )udat_getCalendar (DATE_FORMAT_OBJECT (dfo ));
47
+ udat_parseCalendar (DATE_FORMAT_OBJECT (dfo ), parsed_calendar , text_utf16 , text_utf16_len , parse_pos , & INTL_DATA_ERROR_CODE (dfo ));
48
+ if ( text_utf16 ) {
49
49
efree (text_utf16 );
50
50
}
51
51
INTL_METHOD_CHECK_STATUS ( dfo , "Calendar parsing failed" );
52
52
timestamp = ucal_getMillis ( parsed_calendar , & INTL_DATA_ERROR_CODE (dfo ));
53
53
} else {
54
- timestamp = udat_parse ( DATE_FORMAT_OBJECT (dfo ), text_utf16 , text_utf16_len , parse_pos , & INTL_DATA_ERROR_CODE (dfo ));
55
- if ( text_utf16 ) {
54
+ timestamp = udat_parse (DATE_FORMAT_OBJECT (dfo ), text_utf16 , text_utf16_len , parse_pos , & INTL_DATA_ERROR_CODE (dfo ));
55
+ if ( text_utf16 ) {
56
56
efree (text_utf16 );
57
57
}
58
58
}
@@ -154,12 +154,12 @@ PHP_FUNCTION(datefmt_parse)
154
154
RETURN_FALSE ;
155
155
}
156
156
parse_pos = (int32_t )long_parse_pos ;
157
- if ((size_t )parse_pos > text_len ) {
157
+ if ((size_t )parse_pos > text_len ) {
158
158
RETURN_FALSE ;
159
159
}
160
160
}
161
- internal_parse_to_timestamp ( dfo , text_to_parse , text_len , z_parse_pos ? & parse_pos : NULL , false, return_value );
162
- if (z_parse_pos ) {
161
+ internal_parse_to_timestamp ( dfo , text_to_parse , text_len , z_parse_pos ? & parse_pos : NULL , false, return_value );
162
+ if (z_parse_pos ) {
163
163
zval_ptr_dtor (z_parse_pos );
164
164
ZVAL_LONG (z_parse_pos , parse_pos );
165
165
}
@@ -168,38 +168,44 @@ PHP_FUNCTION(datefmt_parse)
168
168
169
169
PHP_METHOD (IntlDateFormatter , parseToCalendar )
170
170
{
171
- char * text_to_parse = NULL ;
172
- size_t text_len = 0 ;
173
- zval * z_parse_pos = NULL ;
174
- int32_t parse_pos = -1 ;
171
+ zend_string * text_to_parse = NULL ;
172
+ zval * z_parse_pos = NULL ;
173
+ int32_t parse_pos = -1 ;
175
174
176
175
DATE_FORMAT_METHOD_INIT_VARS ;
177
176
178
- /* Parse parameters. */
179
- if ( zend_parse_method_parameters ( ZEND_NUM_ARGS (), getThis (), "Os|z!" ,
180
- & object , IntlDateFormatter_ce_ptr , & text_to_parse , & text_len , & z_parse_pos ) == FAILURE ){
181
- RETURN_THROWS ();
182
- }
177
+ ZEND_PARSE_PARAMETERS_START (1 , 2 )
178
+ Z_PARAM_STR (text_to_parse )
179
+ Z_PARAM_OPTIONAL
180
+ Z_PARAM_ZVAL (z_parse_pos )
181
+ ZEND_PARSE_PARAMETERS_END ();
182
+
183
+ object = ZEND_THIS ;
183
184
184
185
/* Fetch the object. */
185
186
DATE_FORMAT_METHOD_FETCH_OBJECT ;
186
187
187
188
if (z_parse_pos ) {
188
189
zend_long long_parse_pos ;
189
190
ZVAL_DEREF (z_parse_pos );
190
- long_parse_pos = zval_get_long (z_parse_pos );
191
+ bool failed = false;
192
+ long_parse_pos = zval_try_get_long (z_parse_pos , & failed );
193
+ if (failed ) {
194
+ zend_argument_type_error (2 , "must be of type int, %s given" , zend_zval_value_name (z_parse_pos ));
195
+ RETURN_THROWS ();
196
+ }
191
197
if (ZEND_LONG_INT_OVFL (long_parse_pos )) {
192
198
intl_error_set_code (NULL , U_ILLEGAL_ARGUMENT_ERROR );
193
199
intl_error_set_custom_msg (NULL , "String index is out of valid range." , 0 );
194
200
RETURN_FALSE ;
195
201
}
196
202
parse_pos = (int32_t )long_parse_pos ;
197
- if ( (size_t )parse_pos > text_len ) {
203
+ if ( parse_pos != -1 && (size_t )parse_pos > ZSTR_LEN ( text_to_parse ) ) {
198
204
RETURN_FALSE ;
199
205
}
200
206
}
201
- internal_parse_to_timestamp ( dfo , text_to_parse , text_len , z_parse_pos ? & parse_pos : NULL , true, return_value );
202
- if (z_parse_pos ) {
207
+ internal_parse_to_timestamp ( dfo , ZSTR_VAL ( text_to_parse ), ZSTR_LEN ( text_to_parse ) , z_parse_pos ? & parse_pos : NULL , true, return_value );
208
+ if (z_parse_pos ) {
203
209
zval_ptr_dtor (z_parse_pos );
204
210
ZVAL_LONG (z_parse_pos , parse_pos );
205
211
}
0 commit comments