Skip to content

Commit dd62ec0

Browse files
committed
Refactor php_next_utf8_char() to use zend_result
1 parent 95ad1d1 commit dd62ec0

File tree

5 files changed

+10
-11
lines changed

5 files changed

+10
-11
lines changed

ext/json/json_encoder.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@ static int php_json_escape_string(
316316
smart_str *buf, const char *s, size_t len,
317317
int options, php_json_encoder *encoder) /* {{{ */
318318
{
319-
int status;
320319
unsigned int us;
321320
size_t pos, checkpoint;
322321
char *dst;
@@ -371,7 +370,7 @@ static int php_json_escape_string(
371370
}
372371
us = (unsigned char)s[0];
373372
if (UNEXPECTED(us >= 0x80)) {
374-
373+
zend_result status;
375374
us = php_next_utf8_char((unsigned char *)s, len, &pos, &status);
376375

377376
/* check whether UTF8 character is correct */

ext/standard/html.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static inline unsigned int get_next_char(
9595
const unsigned char *str,
9696
size_t str_len,
9797
size_t *cursor,
98-
int *status)
98+
zend_result *status)
9999
{
100100
size_t pos = *cursor;
101101
unsigned int this_char = 0;
@@ -356,7 +356,7 @@ PHPAPI unsigned int php_next_utf8_char(
356356
const unsigned char *str,
357357
size_t str_len,
358358
size_t *cursor,
359-
int *status)
359+
zend_result *status)
360360
{
361361
return get_next_char(cs_utf_8, str, str_len, cursor, status);
362362
}
@@ -1045,8 +1045,8 @@ static inline void find_entity_for_char(
10451045
*entity_len = c->data.ent.entity_len;
10461046
} else {
10471047
/* peek at next char */
1048-
size_t cursor_before = *cursor;
1049-
int status = SUCCESS;
1048+
size_t cursor_before = *cursor;
1049+
zend_result status = SUCCESS;
10501050
unsigned next_char;
10511051

10521052
if (!(*cursor < oldlen))
@@ -1156,7 +1156,7 @@ PHPAPI zend_string *php_escape_html_entities_ex(const unsigned char *old, size_t
11561156
const unsigned char *mbsequence = NULL;
11571157
size_t mbseqlen = 0,
11581158
cursor_before = cursor;
1159-
int status = SUCCESS;
1159+
zend_result status = SUCCESS;
11601160
unsigned int this_char = get_next_char(charset, old, oldlen, &cursor, &status);
11611161

11621162
/* guarantee we have at least 40 bytes to write.

ext/standard/html.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ void register_html_constants(INIT_FUNC_ARGS);
4747
PHPAPI zend_string *php_escape_html_entities(const unsigned char *old, size_t oldlen, int all, int flags, const char *hint_charset);
4848
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);
4949
PHPAPI zend_string *php_unescape_html_entities(zend_string *str, int all, int flags, const char *hint_charset);
50-
PHPAPI unsigned int php_next_utf8_char(const unsigned char *str, size_t str_len, size_t *cursor, int *status);
50+
PHPAPI unsigned int php_next_utf8_char(const unsigned char *str, size_t str_len, size_t *cursor, zend_result *status);
5151

5252
#endif /* HTML_H */

ext/standard/string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6056,7 +6056,7 @@ static zend_string *php_utf8_decode(const char *s, size_t len)
60566056
str = zend_string_alloc(len, 0);
60576057
ZSTR_LEN(str) = 0;
60586058
while (pos < len) {
6059-
int status = FAILURE;
6059+
zend_result status = FAILURE;
60606060
c = php_next_utf8_char((const unsigned char*)s, (size_t) len, &pos, &status);
60616061

60626062
/* The lower 256 codepoints of Unicode are identical to Latin-1,

ext/xml/xml.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,8 @@ static zend_string *xml_utf8_decode(const XML_Char *s, size_t len, const XML_Cha
550550
str = zend_string_alloc(len, 0);
551551
ZSTR_LEN(str) = 0;
552552
while (pos < len) {
553-
int status = FAILURE;
554-
c = php_next_utf8_char((const unsigned char*)s, (size_t) len, &pos, &status);
553+
zend_result status = FAILURE;
554+
c = php_next_utf8_char((const unsigned char*)s, len, &pos, &status);
555555

556556
if (status == FAILURE || c > 0xFFU) {
557557
c = '?';

0 commit comments

Comments
 (0)