Skip to content

Commit cb80540

Browse files
committed
Fix intlcal_roll
1 parent bc6860a commit cb80540

File tree

2 files changed

+19
-48
lines changed

2 files changed

+19
-48
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 & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -427,57 +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 = (zend_bool)-1;
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-
bool_variant_val = Z_TYPE(args[1]) == IS_TRUE? 1 : 0;
455-
} else if (zend_parse_method_parameters(ZEND_NUM_ARGS(), object,
456-
"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) {
457435
RETURN_THROWS();
458436
}
459437

438+
CALENDAR_METHOD_FETCH_OBJECT;
439+
460440
if (field < 0 || field >= UCAL_FIELD_COUNT) {
461-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
462-
"intlcal_roll: invalid field", 0);
441+
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_roll: invalid field", 0);
463442
RETURN_FALSE;
464443
}
465-
if (bool_variant_val == (zend_bool)-1 &&
466-
(value < INT32_MIN || value > INT32_MAX)) {
467-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
468-
"intlcal_roll: value out of bounds", 0);
469-
RETURN_FALSE;
470-
}
471-
472-
CALENDAR_METHOD_FETCH_OBJECT;
473444

474-
if (bool_variant_val != (zend_bool)-1) {
475-
co->ucal->roll((UCalendarDateFields)field, (UBool)bool_variant_val,
476-
CALENDAR_ERROR_CODE(co));
445+
if (Z_TYPE_P(zvalue) == IS_FALSE || Z_TYPE_P(zvalue) == IS_TRUE) {
446+
co->ucal->roll((UCalendarDateFields)field, (UBool) (Z_TYPE_P(zvalue) == IS_TRUE), CALENDAR_ERROR_CODE(co));
477447
} else {
478-
co->ucal->roll((UCalendarDateFields)field, (int32_t)value,
479-
CALENDAR_ERROR_CODE(co));
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+
455+
co->ucal->roll((UCalendarDateFields)field, (int32_t)value, CALENDAR_ERROR_CODE(co));
480456
}
457+
481458
INTL_METHOD_CHECK_STATUS(co, "intlcal_roll: Error calling ICU Calendar::roll");
482459

483460
RETURN_TRUE;

0 commit comments

Comments
 (0)