From c43aeabc4466b50325d1ab7931c712bf2c49f926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 21 Jun 2026 23:04:06 +0200 Subject: [PATCH 1/2] zend_ast: Make `s` a `const zend_string*` in `zend_ast_export_quoted_str()` Following php/php-src#22350. --- Zend/zend_ast.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index 57faedc06f9b..d844db77b4b9 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -1636,7 +1636,7 @@ static ZEND_COLD void zend_ast_export_qstr(smart_str *str, char quote, const zen } } -static ZEND_COLD void zend_ast_export_quoted_str(smart_str *str, zend_string *s) +static ZEND_COLD void zend_ast_export_quoted_str(smart_str *str, const zend_string *s) { size_t i; From 1d636333543db51e93d6ad5d661b7a023d0a836a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 21 Jun 2026 23:04:43 +0200 Subject: [PATCH 2/2] zend_ast: Reduce variable scope in `zend_ast_export_*str()` --- Zend/zend_ast.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index d844db77b4b9..9397ba42da8c 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -1578,9 +1578,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio static ZEND_COLD void zend_ast_export_str(smart_str *str, const zend_string *s) { - size_t i; - - for (i = 0; i < ZSTR_LEN(s); i++) { + for (size_t i = 0; i < ZSTR_LEN(s); i++) { unsigned char c = ZSTR_VAL(s)[i]; if (c == '\'' || c == '\\') { smart_str_appendc(str, '\\'); @@ -1593,9 +1591,7 @@ static ZEND_COLD void zend_ast_export_str(smart_str *str, const zend_string *s) static ZEND_COLD void zend_ast_export_qstr(smart_str *str, char quote, const zend_string *s) { - size_t i; - - for (i = 0; i < ZSTR_LEN(s); i++) { + for (size_t i = 0; i < ZSTR_LEN(s); i++) { unsigned char c = ZSTR_VAL(s)[i]; if (c < ' ') { switch (c) { @@ -1638,10 +1634,9 @@ static ZEND_COLD void zend_ast_export_qstr(smart_str *str, char quote, const zen static ZEND_COLD void zend_ast_export_quoted_str(smart_str *str, const zend_string *s) { - size_t i; - - for (i = 0; i < ZSTR_LEN(s); i++) { - if ((unsigned char) ZSTR_VAL(s)[i] < ' ') { + for (size_t i = 0; i < ZSTR_LEN(s); i++) { + unsigned char c = ZSTR_VAL(s)[i]; + if (c < ' ') { smart_str_appendc(str, '"'); zend_ast_export_qstr(str, '"', s); smart_str_appendc(str, '"');