Skip to content

Commit c6ff115

Browse files
committed
Fix intlcal_roll
1 parent 3c87481 commit c6ff115

File tree

2 files changed

+19
-42
lines changed

2 files changed

+19
-42
lines changed

Zend/tests/arginfo_zpp_mismatch.phpt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,14 @@ Test that there is no arginfo/zpp mismatch
33
--FILE--
44
<?php
55

6-
set_error_handler(
7-
function (string $code, string $message) {
8-
return true;
9-
},
10-
E_NOTICE | E_WARNING
11-
);
12-
136
foreach (get_defined_functions()["internal"] as $function) {
147
try {
15-
$function(null, null, null, null, null, null, null, null);
8+
@$function(null, null, null, null, null, null, null, null);
169
} catch (ArgumentCountError|Error) {
1710
}
1811
}
1912

13+
// var_dump() and debug_zval_dump() print all arguments
2014
?>
2115
--EXPECT--
2216
NULL

ext/intl/calendar/calendar_methods.cpp

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -427,51 +427,34 @@ U_CFUNC PHP_FUNCTION(intlcal_set)
427427

428428
U_CFUNC PHP_FUNCTION(intlcal_roll)
429429
{
430-
zend_long field,
431-
value;
432-
zval args_a[3] = {0},
433-
*args = args_a;
434-
zend_bool bool_variant_val;
430+
zval *zvalue;
431+
zend_long field, value;
435432
CALENDAR_METHOD_INIT_VARS;
436433

437-
object = getThis();
438-
439-
if (ZEND_NUM_ARGS() > (object ? 2 :3) ||
440-
zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) {
441-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
442-
"intlcal_set: too many arguments", 0);
443-
RETURN_FALSE;
444-
}
445-
if (!object) {
446-
args++;
447-
}
448-
if (!Z_ISUNDEF(args[1]) && (Z_TYPE(args[1]) == IS_TRUE || Z_TYPE(args[1]) == IS_FALSE)) {
449-
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), object,
450-
"Olb", &object, Calendar_ce_ptr, &field, &bool_variant_val)
451-
== FAILURE) {
452-
RETURN_THROWS();
453-
}
454-
/* false corresponds to rolling down, i.e. -1 */
455-
value = Z_TYPE(args[1]) == IS_TRUE? 1 : -1;
456-
} else if (zend_parse_method_parameters(ZEND_NUM_ARGS(), object,
457-
"Oll", &object, Calendar_ce_ptr, &field, &value) == FAILURE) {
434+
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Olz", &object, Calendar_ce_ptr, &field, &zvalue) == FAILURE) {
458435
RETURN_THROWS();
459436
}
460437

438+
CALENDAR_METHOD_FETCH_OBJECT;
439+
461440
if (field < 0 || field >= UCAL_FIELD_COUNT) {
462-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
463-
"intlcal_roll: invalid field", 0);
464-
RETURN_FALSE;
465-
}
466-
if (value < INT32_MIN || value > INT32_MAX) {
467-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
468-
"intlcal_roll: value out of bounds", 0);
441+
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_roll: invalid field", 0);
469442
RETURN_FALSE;
470443
}
471444

472-
CALENDAR_METHOD_FETCH_OBJECT;
445+
if (Z_TYPE_P(zvalue) == IS_FALSE || Z_TYPE_P(zvalue) == IS_TRUE) {
446+
value = Z_TYPE_P(zvalue) == IS_TRUE ? 1 : -1;
447+
} else {
448+
value = zval_get_long(zvalue);
449+
450+
if (value < INT32_MIN || value > INT32_MAX) {
451+
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_roll: value out of bounds", 0);
452+
RETURN_FALSE;
453+
}
454+
}
473455

474456
co->ucal->roll((UCalendarDateFields)field, (int32_t)value, CALENDAR_ERROR_CODE(co));
457+
475458
INTL_METHOD_CHECK_STATUS(co, "intlcal_roll: Error calling ICU Calendar::roll");
476459

477460
RETURN_TRUE;

0 commit comments

Comments
 (0)