Skip to content

Commit 8d98f72

Browse files
authored
Use ZSTR_IS_VALID_UTF8 macro where possible (#12869)
1 parent b532b9a commit 8d98f72

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

ext/mbstring/mbstring.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,7 @@ static size_t mb_get_strlen(zend_string *string, const mbfl_encoding *encoding)
18141814
unsigned int char_len = encoding->flag & (MBFL_ENCTYPE_SBCS | MBFL_ENCTYPE_WCS2 | MBFL_ENCTYPE_WCS4);
18151815
if (char_len) {
18161816
return ZSTR_LEN(string) / char_len;
1817-
} else if (php_mb_is_no_encoding_utf8(encoding->no_encoding) && GC_FLAGS(string) & IS_STR_VALID_UTF8) {
1817+
} else if (php_mb_is_no_encoding_utf8(encoding->no_encoding) && ZSTR_IS_VALID_UTF8(string)) {
18181818
return mb_fast_strlen_utf8((unsigned char*)ZSTR_VAL(string), ZSTR_LEN(string));
18191819
}
18201820

@@ -2263,7 +2263,7 @@ PHP_FUNCTION(mb_substr_count)
22632263
if (php_mb_is_no_encoding_utf8(enc->no_encoding)) {
22642264
/* No need to do any conversion if haystack/needle are already known-valid UTF-8
22652265
* (If they are not valid, then not passing them through conversion filters could affect output) */
2266-
if (GC_FLAGS(haystack) & IS_STR_VALID_UTF8) {
2266+
if (ZSTR_IS_VALID_UTF8(haystack)) {
22672267
haystack_u8 = haystack;
22682268
} else {
22692269
unsigned int num_errors = 0;
@@ -2273,7 +2273,7 @@ PHP_FUNCTION(mb_substr_count)
22732273
}
22742274
}
22752275

2276-
if (GC_FLAGS(needle) & IS_STR_VALID_UTF8) {
2276+
if (ZSTR_IS_VALID_UTF8(needle)) {
22772277
needle_u8 = needle;
22782278
} else {
22792279
unsigned int num_errors = 0;
@@ -3425,7 +3425,7 @@ PHP_FUNCTION(mb_detect_encoding)
34253425
strict = MBSTRG(strict_detection);
34263426
}
34273427

3428-
if (size == 1 && *elist == &mbfl_encoding_utf8 && (GC_FLAGS(str) & IS_STR_VALID_UTF8)) {
3428+
if (size == 1 && *elist == &mbfl_encoding_utf8 && ZSTR_IS_VALID_UTF8(str)) {
34293429
ret = &mbfl_encoding_utf8;
34303430
} else {
34313431
ret = mb_guess_encoding((unsigned char*)ZSTR_VAL(str), ZSTR_LEN(str), elist, size, strict, order_significant);
@@ -5495,7 +5495,7 @@ static bool mb_fast_check_utf8_avx2(zend_string *str)
54955495
static bool mb_check_str_encoding(zend_string *str, const mbfl_encoding *encoding)
54965496
{
54975497
if (encoding == &mbfl_encoding_utf8) {
5498-
if (GC_FLAGS(str) & IS_STR_VALID_UTF8) {
5498+
if (ZSTR_IS_VALID_UTF8(str)) {
54995499
return true;
55005500
}
55015501
bool result = mb_fast_check_utf8(str);
@@ -5888,7 +5888,7 @@ PHP_FUNCTION(mb_scrub)
58885888
RETURN_THROWS();
58895889
}
58905890

5891-
if (enc == &mbfl_encoding_utf8 && (GC_FLAGS(str) & IS_STR_VALID_UTF8)) {
5891+
if (enc == &mbfl_encoding_utf8 && ZSTR_IS_VALID_UTF8(str)) {
58925892
/* A valid UTF-8 string will not be changed by mb_scrub; so just increment the refcount and return it */
58935893
RETURN_STR_COPY(str);
58945894
}

ext/pcre/php_pcre.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ *
11121112

11131113
static zend_always_inline bool is_known_valid_utf8(
11141114
zend_string *subject_str, PCRE2_SIZE start_offset) {
1115-
if (!(GC_FLAGS(subject_str) & IS_STR_VALID_UTF8)) {
1115+
if (!ZSTR_IS_VALID_UTF8(subject_str)) {
11161116
/* We don't know whether the string is valid UTF-8 or not. */
11171117
return 0;
11181118
}

0 commit comments

Comments
 (0)