Skip to content

Commit

Permalink
Fix Intl Calendar::roll() method
Browse files Browse the repository at this point in the history
This code really needs to be review as it's convoluted for no good reason
  • Loading branch information
Girgias committed Jun 2, 2020
1 parent 09409dc commit 5656643
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions ext/intl/calendar/calendar_methods.cpp
Expand Up @@ -431,7 +431,7 @@ U_CFUNC PHP_FUNCTION(intlcal_roll)
value;
zval args_a[3] = {0},
*args = args_a;
zend_bool bool_variant_val = (zend_bool)-1;
zend_bool bool_variant_val;
CALENDAR_METHOD_INIT_VARS;

object = getThis();
Expand All @@ -451,7 +451,8 @@ U_CFUNC PHP_FUNCTION(intlcal_roll)
== FAILURE) {
RETURN_THROWS();
}
bool_variant_val = Z_TYPE(args[1]) == IS_TRUE? 1 : 0;
/* false corresponds to rolling down, i.e. -1 */
value = Z_TYPE(args[1]) == IS_TRUE? 1 : -1;
} else if (zend_parse_method_parameters(ZEND_NUM_ARGS(), object,
"Oll", &object, Calendar_ce_ptr, &field, &value) == FAILURE) {
RETURN_THROWS();
Expand All @@ -462,22 +463,15 @@ U_CFUNC PHP_FUNCTION(intlcal_roll)
"intlcal_roll: invalid field", 0);
RETURN_FALSE;
}
if (bool_variant_val == (zend_bool)-1 &&
(value < INT32_MIN || value > INT32_MAX)) {
if (value < INT32_MIN || value > INT32_MAX) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"intlcal_roll: value out of bounds", 0);
RETURN_FALSE;
}

CALENDAR_METHOD_FETCH_OBJECT;

if (bool_variant_val != (zend_bool)-1) {
co->ucal->roll((UCalendarDateFields)field, (UBool)bool_variant_val,
CALENDAR_ERROR_CODE(co));
} else {
co->ucal->roll((UCalendarDateFields)field, (int32_t)value,
CALENDAR_ERROR_CODE(co));
}
co->ucal->roll((UCalendarDateFields)field, (int32_t)value, CALENDAR_ERROR_CODE(co));
INTL_METHOD_CHECK_STATUS(co, "intlcal_roll: Error calling ICU Calendar::roll");

RETURN_TRUE;
Expand Down

0 comments on commit 5656643

Please sign in to comment.