Refactor php_next_utf8_char() to use zend_result

This commit is contained in:
George Peter Banyard 2022-03-13 13:48:21 +00:00
parent 95ad1d1cbc
commit dd62ec065e
No known key found for this signature in database
GPG Key ID: 3306078E3194AEBD
5 changed files with 10 additions and 11 deletions

View File

@ -316,7 +316,6 @@ static int php_json_escape_string(
smart_str *buf, const char *s, size_t len,
int options, php_json_encoder *encoder) /* {{{ */
{
int status;
unsigned int us;
size_t pos, checkpoint;
char *dst;
@ -371,7 +370,7 @@ static int php_json_escape_string(
}
us = (unsigned char)s[0];
if (UNEXPECTED(us >= 0x80)) {
zend_result status;
us = php_next_utf8_char((unsigned char *)s, len, &pos, &status);
/* check whether UTF8 character is correct */

View File

@ -95,7 +95,7 @@ static inline unsigned int get_next_char(
const unsigned char *str,
size_t str_len,
size_t *cursor,
int *status)
zend_result *status)
{
size_t pos = *cursor;
unsigned int this_char = 0;
@ -356,7 +356,7 @@ PHPAPI unsigned int php_next_utf8_char(
const unsigned char *str,
size_t str_len,
size_t *cursor,
int *status)
zend_result *status)
{
return get_next_char(cs_utf_8, str, str_len, cursor, status);
}
@ -1045,8 +1045,8 @@ static inline void find_entity_for_char(
*entity_len = c->data.ent.entity_len;
} else {
/* peek at next char */
size_t cursor_before = *cursor;
int status = SUCCESS;
size_t cursor_before = *cursor;
zend_result status = SUCCESS;
unsigned next_char;
if (!(*cursor < oldlen))
@ -1156,7 +1156,7 @@ PHPAPI zend_string *php_escape_html_entities_ex(const unsigned char *old, size_t
const unsigned char *mbsequence = NULL;
size_t mbseqlen = 0,
cursor_before = cursor;
int status = SUCCESS;
zend_result status = SUCCESS;
unsigned int this_char = get_next_char(charset, old, oldlen, &cursor, &status);
/* guarantee we have at least 40 bytes to write.

View File

@ -47,6 +47,6 @@ void register_html_constants(INIT_FUNC_ARGS);
PHPAPI zend_string *php_escape_html_entities(const unsigned char *old, size_t oldlen, int all, int flags, const char *hint_charset);
PHPAPI zend_string *php_escape_html_entities_ex(const unsigned char *old, size_t oldlen, int all, int flags, const char *hint_charset, bool double_encode, bool quiet);
PHPAPI zend_string *php_unescape_html_entities(zend_string *str, int all, int flags, const char *hint_charset);
PHPAPI unsigned int php_next_utf8_char(const unsigned char *str, size_t str_len, size_t *cursor, int *status);
PHPAPI unsigned int php_next_utf8_char(const unsigned char *str, size_t str_len, size_t *cursor, zend_result *status);
#endif /* HTML_H */

View File

@ -6056,7 +6056,7 @@ static zend_string *php_utf8_decode(const char *s, size_t len)
str = zend_string_alloc(len, 0);
ZSTR_LEN(str) = 0;
while (pos < len) {
int status = FAILURE;
zend_result status = FAILURE;
c = php_next_utf8_char((const unsigned char*)s, (size_t) len, &pos, &status);
/* The lower 256 codepoints of Unicode are identical to Latin-1,

View File

@ -550,8 +550,8 @@ static zend_string *xml_utf8_decode(const XML_Char *s, size_t len, const XML_Cha
str = zend_string_alloc(len, 0);
ZSTR_LEN(str) = 0;
while (pos < len) {
int status = FAILURE;
c = php_next_utf8_char((const unsigned char*)s, (size_t) len, &pos, &status);
zend_result status = FAILURE;
c = php_next_utf8_char((const unsigned char*)s, len, &pos, &status);
if (status == FAILURE || c > 0xFFU) {
c = '?';