Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ PHP NEWS
- Zip:
. Fixed bug GH-21705 (ZipArchive::getFromIndex() ignores
ZipArchive::FL_UNCHANGED for deleted entries). (Weilin Du)
. Fixed bug GH-22176 (memory leak with ZipArchive::registerCancelBack()
is used with reference returning function during shutdown).
(David Carlier)

02 Jul 2026, PHP 8.6.0alpha1

Expand Down
10 changes: 5 additions & 5 deletions ext/intl/breakiterator/codepointiterator_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void CodePointBreakIterator::setText(const UnicodeString &text)

void CodePointBreakIterator::setText(UText *text, UErrorCode &status)
{
if (U_FAILURE(status)) {
if (UNEXPECTED(U_FAILURE(status))) {
return;
}

Expand Down Expand Up @@ -234,7 +234,7 @@ CodePointBreakIterator *CodePointBreakIterator::createBufferClone(
void *stackBuffer, int32_t &bufferSize, UErrorCode &status)
{
//see implementation of RuleBasedBreakIterator::createBufferClone()
if (U_FAILURE(status)) {
if (UNEXPECTED(U_FAILURE(status))) {
return NULL;
}

Expand Down Expand Up @@ -273,17 +273,17 @@ CodePointBreakIterator *CodePointBreakIterator::createBufferClone(
CodePointBreakIterator &CodePointBreakIterator::refreshInputText(UText *input, UErrorCode &status)
{
//see implementation of RuleBasedBreakIterator::createBufferClone()
if (U_FAILURE(status)) {
if (UNEXPECTED(U_FAILURE(status))) {
return *this;
}
if (input == NULL) {
if (UNEXPECTED(input == NULL)) {
status = U_ILLEGAL_ARGUMENT_ERROR;
return *this;
}

int64_t pos = utext_getNativeIndex(this->fText);
this->fText = utext_clone(this->fText, input, false, true, &status);
if (U_FAILURE(status)) {
if (UNEXPECTED(U_FAILURE(status))) {
return *this;
}

Expand Down
8 changes: 4 additions & 4 deletions ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, __construct)
if (!compiled) {
UnicodeString rulesStr;
UParseError parseError = UParseError();
if (intl_stringFromChar(rulesStr, ZSTR_VAL(rules), ZSTR_LEN(rules), &status) == FAILURE) {
if (UNEXPECTED(intl_stringFromChar(rulesStr, ZSTR_VAL(rules), ZSTR_LEN(rules), &status) == FAILURE)) {
zend_throw_exception(IntlException_ce_ptr,
"IntlRuleBasedBreakIterator::__construct(): rules were not a valid UTF-8 string", 0);
RETURN_THROWS();
}

rbbi = new RuleBasedBreakIterator(rulesStr, parseError, status);
intl_error_set_code(NULL, status);
if (U_FAILURE(status)) {
if (UNEXPECTED(U_FAILURE(status))) {
smart_str parse_error_str;
parse_error_str = intl_parse_error_to_string(&parseError);
zend_throw_exception_ex(IntlException_ce_ptr, 0,
Expand All @@ -78,7 +78,7 @@ U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, __construct)
}
} else { // compiled
rbbi = new RuleBasedBreakIterator(reinterpret_cast<uint8_t *>(ZSTR_VAL(rules)), ZSTR_LEN(rules), status);
if (U_FAILURE(status)) {
if (UNEXPECTED(U_FAILURE(status))) {
zend_throw_exception(IntlException_ce_ptr,
"IntlRuleBasedBreakIterator::__construct(): unable to create instance from compiled rules", 0);
delete rbbi;
Expand Down Expand Up @@ -165,7 +165,7 @@ U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, getBinaryRules)
uint32_t rules_len;
const uint8_t *rules = fetch_rbbi(bio)->getBinaryRules(rules_len);

if (rules_len > INT_MAX - 1) {
if (UNEXPECTED(rules_len > INT_MAX - 1)) {
intl_errors_set(BREAKITER_ERROR_P(bio), BREAKITER_ERROR_CODE(bio),
"the rules are too large");
RETURN_FALSE;
Expand Down
2 changes: 1 addition & 1 deletion ext/intl/common/common_date.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ U_CFUNC TimeZone *timezone_convert_datetimezone(
minutes = offset_mins - hours * 60;
minutes *= minutes > 0 ? 1 : -1;

if (offset_mins <= -24 * 60 || offset_mins >= 24 * 60) {
if (UNEXPECTED(offset_mins <= -24 * 60 || offset_mins >= 24 * 60)) {
intl_errors_set(outside_error, U_ILLEGAL_ARGUMENT_ERROR,
"object has an time zone offset that's too large");
return NULL;
Expand Down
6 changes: 3 additions & 3 deletions ext/intl/converter/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static void php_converter_append_toUnicode_target(zval *val, UConverterToUnicode
case IS_LONG:
{
const zend_long lval = Z_LVAL_P(val);
if ((lval < 0) || (lval > 0x10FFFF)) {
if (UNEXPECTED((lval < 0) || (lval > 0x10FFFF))) {
php_converter_throw_failure(objval, U_ILLEGAL_ARGUMENT_ERROR, "Invalid codepoint U+%04lx", lval);
return;
}
Expand Down Expand Up @@ -636,7 +636,7 @@ static zend_string* php_converter_do_convert(UConverter *dest_cnv,
zend_string *ret;
UChar *temp;

if (!src_cnv || !dest_cnv) {
if (UNEXPECTED(!src_cnv || !dest_cnv)) {
php_converter_throw_failure(objval, U_INVALID_STATE_ERROR,
"Internal converters not initialized");
return nullptr;
Expand Down Expand Up @@ -686,7 +686,7 @@ static zend_string* php_converter_do_convert(UConverter *dest_cnv,

static void php_converter_set_subst_chars(UConverter *cnv, const zend_string *subst, UErrorCode *error)
{
if (ZSTR_LEN(subst) > SCHAR_MAX) {
if (UNEXPECTED(ZSTR_LEN(subst) > SCHAR_MAX)) {
*error = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
Expand Down
4 changes: 2 additions & 2 deletions ext/intl/dateformat/dateformat_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ static int32_t internal_get_arr_ele(IntlDateFormatter_object *dfo,
intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR, message);
efree(message);
} else {
if (Z_LVAL_P(ele_value) > INT32_MAX ||
Z_LVAL_P(ele_value) < INT32_MIN) {
if (UNEXPECTED(Z_LVAL_P(ele_value) > INT32_MAX ||
Z_LVAL_P(ele_value) < INT32_MIN)) {
spprintf(&message, 0, "value " ZEND_LONG_FMT " is out of "
"bounds for a 32-bit integer in key '%s'",
Z_LVAL_P(ele_value), key_name);
Expand Down
4 changes: 2 additions & 2 deletions ext/intl/formatter/formatter_attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ U_CFUNC PHP_FUNCTION( numfmt_get_symbol )

UNumberFormatSymbol symbol = static_cast<UNumberFormatSymbol>(lsymbol);

if(symbol >= UNUM_FORMAT_SYMBOL_COUNT || symbol < 0) {
if (UNEXPECTED(symbol >= UNUM_FORMAT_SYMBOL_COUNT || symbol < 0)) {
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "invalid symbol value");
RETURN_FALSE;
}
Expand Down Expand Up @@ -276,7 +276,7 @@ U_CFUNC PHP_FUNCTION( numfmt_set_symbol )

UNumberFormatSymbol symbol = static_cast<UNumberFormatSymbol>(lsymbol);

if (symbol >= UNUM_FORMAT_SYMBOL_COUNT || symbol < 0) {
if (UNEXPECTED(symbol >= UNUM_FORMAT_SYMBOL_COUNT || symbol < 0)) {
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "invalid symbol value");
RETURN_FALSE;
}
Expand Down
4 changes: 2 additions & 2 deletions ext/intl/formatter/formatter_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ U_CFUNC PHP_FUNCTION( numfmt_parse )

if (zposition) {
zend_long long_position = zval_get_long(zposition);
if (long_position < INT32_MIN || long_position > INT32_MAX) {
if (UNEXPECTED(long_position < INT32_MIN || long_position > INT32_MAX)) {
zend_argument_value_error(hasThis() ? 3 : 4, "must be between %d and %d", INT32_MIN, INT32_MAX);
RETURN_THROWS();
}
Expand Down Expand Up @@ -162,7 +162,7 @@ U_CFUNC PHP_FUNCTION( numfmt_parse_currency )

if (zposition) {
zend_long long_position = zval_get_long(zposition);
if (long_position < INT32_MIN || long_position > INT32_MAX) {
if (UNEXPECTED(long_position < INT32_MIN || long_position > INT32_MAX)) {
zend_argument_value_error(hasThis() ? 3 : 4, "must be between %d and %d", INT32_MIN, INT32_MAX);
RETURN_THROWS();
}
Expand Down
26 changes: 13 additions & 13 deletions ext/intl/grapheme/grapheme_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ U_CFUNC PHP_FUNCTION(grapheme_strpos)
Z_PARAM_PATH(locale, locale_len)
ZEND_PARSE_PARAMETERS_END();

if ( OUTSIDE_STRING(loffset, haystack_len) ) {
if (UNEXPECTED(OUTSIDE_STRING(loffset, haystack_len))) {
zend_argument_value_error(3, "must be contained in argument #1 ($haystack)");
RETURN_THROWS();
}
Expand Down Expand Up @@ -158,7 +158,7 @@ U_CFUNC PHP_FUNCTION(grapheme_stripos)
Z_PARAM_PATH(locale, locale_len)
ZEND_PARSE_PARAMETERS_END();

if ( OUTSIDE_STRING(loffset, haystack_len) ) {
if (UNEXPECTED(OUTSIDE_STRING(loffset, haystack_len))) {
zend_argument_value_error(3, "must be contained in argument #1 ($haystack)");
RETURN_THROWS();
}
Expand Down Expand Up @@ -224,7 +224,7 @@ U_CFUNC PHP_FUNCTION(grapheme_strrpos)
Z_PARAM_PATH(locale, locale_len)
ZEND_PARSE_PARAMETERS_END();

if ( OUTSIDE_STRING(loffset, haystack_len) ) {
if (UNEXPECTED(OUTSIDE_STRING(loffset, haystack_len))) {
zend_argument_value_error(3, "must be contained in argument #1 ($haystack)");
RETURN_THROWS();
}
Expand Down Expand Up @@ -283,7 +283,7 @@ U_CFUNC PHP_FUNCTION(grapheme_strripos)
Z_PARAM_PATH(locale, locale_len)
ZEND_PARSE_PARAMETERS_END();

if ( OUTSIDE_STRING(loffset, haystack_len) ) {
if (UNEXPECTED(OUTSIDE_STRING(loffset, haystack_len))) {
zend_argument_value_error(3, "must be contained in argument #1 ($haystack)");
RETURN_THROWS();
}
Expand Down Expand Up @@ -358,7 +358,7 @@ U_CFUNC PHP_FUNCTION(grapheme_substr)
Z_PARAM_PATH(locale, locale_len)
ZEND_PARSE_PARAMETERS_END();

if (lstart < INT32_MIN || lstart > INT32_MAX) {
if (UNEXPECTED(lstart < INT32_MIN || lstart > INT32_MAX)) {
zend_argument_value_error(2, "is too large");
RETURN_THROWS();
}
Expand All @@ -369,7 +369,7 @@ U_CFUNC PHP_FUNCTION(grapheme_substr)
length = str_len;
}

if (length < INT32_MIN || length > INT32_MAX) {
if (UNEXPECTED(length < INT32_MIN || length > INT32_MAX)) {
zend_argument_value_error(3, "is too large");
RETURN_THROWS();
}
Expand Down Expand Up @@ -758,17 +758,17 @@ U_CFUNC PHP_FUNCTION(grapheme_extract)
RETURN_THROWS();
}

if ( lstart > INT32_MAX || lstart < 0 || (size_t)lstart >= str_len ) {
if (UNEXPECTED(lstart > INT32_MAX || lstart < 0 || (size_t)lstart >= str_len)) {
intl_error_set( nullptr, U_ILLEGAL_ARGUMENT_ERROR, "start not contained in string");
RETURN_FALSE;
}

if (size < 0) {
if (UNEXPECTED(size < 0)) {
zend_argument_value_error(2, "must be greater than or equal to 0");
RETURN_THROWS();
}

if (size > INT32_MAX) {
if (UNEXPECTED(size > INT32_MAX)) {
zend_argument_value_error(2, "is too large");
RETURN_THROWS();
}
Expand Down Expand Up @@ -864,7 +864,7 @@ U_CFUNC PHP_FUNCTION(grapheme_str_split)
Z_PARAM_LONG(split_len)
ZEND_PARSE_PARAMETERS_END();

if (split_len <= 0 || split_len > UINT_MAX / 4) {
if (UNEXPECTED(split_len <= 0 || split_len > UINT_MAX / 4)) {
zend_argument_value_error(2, "must be greater than 0 and less than or equal to %d", UINT_MAX / 4);
RETURN_THROWS();
}
Expand Down Expand Up @@ -943,17 +943,17 @@ U_CFUNC PHP_FUNCTION(grapheme_levenshtein)
Z_PARAM_PATH(locale, locale_len)
ZEND_PARSE_PARAMETERS_END();

if (cost_ins <= 0 || cost_ins > UINT_MAX / 4) {
if (UNEXPECTED(cost_ins <= 0 || cost_ins > UINT_MAX / 4)) {
zend_argument_value_error(3, "must be greater than 0 and less than or equal to %d", UINT_MAX / 4);
RETURN_THROWS();
}

if (cost_rep <= 0 || cost_rep > UINT_MAX / 4) {
if (UNEXPECTED(cost_rep <= 0 || cost_rep > UINT_MAX / 4)) {
zend_argument_value_error(4, "must be greater than 0 and less than or equal to %d", UINT_MAX / 4);
RETURN_THROWS();
}

if (cost_del <= 0 || cost_del > UINT_MAX / 4) {
if (UNEXPECTED(cost_del <= 0 || cost_del > UINT_MAX / 4)) {
zend_argument_value_error(5, "must be greater than 0 and less than or equal to %d", UINT_MAX / 4);
RETURN_THROWS();
}
Expand Down
2 changes: 1 addition & 1 deletion ext/intl/grapheme/grapheme_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ U_CFUNC void grapheme_substr_ascii(char *str, size_t str_len, int32_t f, int32_t
int32_t str_len2 = (int32_t)str_len; /* in order to avoid signed/unsigned problems */
*sub_str = NULL;

if(str_len > INT32_MAX) {
if (UNEXPECTED(str_len > INT32_MAX)) {
/* We cannot return long strings from ICU functions, so we won't here too */
return;
}
Expand Down
10 changes: 5 additions & 5 deletions ext/intl/idn/idn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ enum {
static zend_result php_intl_idn_check_status(UErrorCode err, const char *msg)
{
intl_error_set_code(NULL, err);
if (U_FAILURE(err)) {
if (UNEXPECTED(U_FAILURE(err))) {
intl_error_set_custom_msg(NULL, msg);
return FAILURE;
}
Expand All @@ -59,7 +59,7 @@ static void php_intl_idn_to_46(INTERNAL_FUNCTION_PARAMETERS,
UIDNAInfo info = UIDNA_INFO_INITIALIZER;

uts46 = uidna_openUTS46(option, &status);
if (php_intl_idn_check_status(status, "failed to open UIDNA instance") == FAILURE) {
if (UNEXPECTED(php_intl_idn_check_status(status, "failed to open UIDNA instance") == FAILURE)) {
RETURN_FALSE;
}

Expand All @@ -74,7 +74,7 @@ static void php_intl_idn_to_46(INTERNAL_FUNCTION_PARAMETERS,
len = uidna_nameToUnicodeUTF8(uts46, ZSTR_VAL(domain), ZSTR_LEN(domain),
ZSTR_VAL(buffer), buffer_capac, &info, &status);
}
if (len >= buffer_capac || php_intl_idn_check_status(status, "failed to convert name") == FAILURE) {
if (UNEXPECTED(len >= buffer_capac || php_intl_idn_check_status(status, "failed to convert name") == FAILURE)) {
uidna_close(uts46);
zend_string_efree(buffer);
RETURN_FALSE;
Expand Down Expand Up @@ -121,7 +121,7 @@ static void php_intl_idn_handoff(INTERNAL_FUNCTION_PARAMETERS, int mode)
zend_argument_must_not_be_empty_error(1);
RETURN_THROWS();
}
if (ZSTR_LEN(domain) > INT32_MAX - 1) {
if (UNEXPECTED(ZSTR_LEN(domain) > INT32_MAX - 1)) {
zend_argument_value_error(1, "must be less than " PRId32 " bytes", INT32_MAX);
RETURN_THROWS();
}
Expand All @@ -133,7 +133,7 @@ static void php_intl_idn_handoff(INTERNAL_FUNCTION_PARAMETERS, int mode)

if (idna_info != NULL) {
idna_info = zend_try_array_init(idna_info);
if (!idna_info) {
if (UNEXPECTED(!idna_info)) {
RETURN_THROWS();
}
}
Expand Down
4 changes: 2 additions & 2 deletions ext/intl/intl_convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void intl_convert_utf8_to_utf16(
*/
*status = U_ZERO_ERROR;

if(src_len > INT32_MAX) {
if (UNEXPECTED(src_len > INT32_MAX)) {
/* we cannot fit this string */
*status = U_BUFFER_OVERFLOW_ERROR;
return;
Expand Down Expand Up @@ -120,7 +120,7 @@ zend_string *intl_convert_utf8_to_utf16_zstr(

*status = U_ZERO_ERROR;

if(src_len > INT32_MAX) {
if (UNEXPECTED(src_len > INT32_MAX)) {
/* we cannot fit this string */
*status = U_BUFFER_OVERFLOW_ERROR;
return NULL;
Expand Down
4 changes: 2 additions & 2 deletions ext/intl/intl_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ typedef struct _intl_data {
#define INTL_MAX_LOCALE_LEN (ULOC_FULLNAME_CAPACITY-1)

#define INTL_CHECK_LOCALE_LEN(locale_len) \
if((locale_len) > INTL_MAX_LOCALE_LEN) { \
if (UNEXPECTED((locale_len) > INTL_MAX_LOCALE_LEN)) { \
char *_msg; \
spprintf(&_msg, 0, "Locale string too long, should be no longer than %d characters", INTL_MAX_LOCALE_LEN); \
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, _msg); \
Expand All @@ -123,7 +123,7 @@ typedef struct _intl_data {
}

#define INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len) \
if((locale_len) > INTL_MAX_LOCALE_LEN) { \
if (UNEXPECTED((locale_len) > INTL_MAX_LOCALE_LEN)) { \
char *_msg; \
spprintf(&_msg, 0, "Locale string too long, should be no longer than %d characters", INTL_MAX_LOCALE_LEN); \
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, _msg); \
Expand Down
2 changes: 1 addition & 1 deletion ext/intl/listformatter/listformatter_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ PHP_METHOD(IntlListFormatter, __construct)
locale = (char *)intl_locale_get_default();
}

if (locale_len > INTL_MAX_LOCALE_LEN) {
if (UNEXPECTED(locale_len > INTL_MAX_LOCALE_LEN)) {
zend_argument_value_error(1, "must be less than or equal to %d characters", INTL_MAX_LOCALE_LEN);
RETURN_THROWS();
}
Expand Down
Loading