|
28 | 28 | #include "zend_API.h" |
29 | 29 | #include "zend_exceptions.h" |
30 | 30 | #include "zend_interfaces.h" |
| 31 | +#include "zend_types.h" |
31 | 32 | #include "zend_virtual_cwd.h" |
32 | 33 | #include "zend_multibyte.h" |
33 | 34 | #include "zend_language_scanner.h" |
@@ -4960,25 +4961,24 @@ static zend_result zend_compile_func_printf(znode *result, zend_ast_list *args) |
4960 | 4961 | * In this case, just emit ECHO and return the string length if needed. */ |
4961 | 4962 | if (args->children == 1) { |
4962 | 4963 | zend_eval_const_expr(&args->child[0]); |
4963 | | - if (args->child[0]->kind == ZEND_AST_ZVAL) { |
4964 | | - zval *format_string = zend_ast_get_zval(args->child[0]); |
4965 | | - if (Z_TYPE_P(format_string) == IS_STRING) { |
4966 | | - /* Check if there are any format specifiers */ |
4967 | | - char *p = Z_STRVAL_P(format_string); |
4968 | | - char *end = p + Z_STRLEN_P(format_string); |
4969 | | - |
4970 | | - if (!memchr(p, '%', end - p)) { |
4971 | | - /* No format specifiers - just emit ECHO and return string length */ |
4972 | | - znode format_node; |
4973 | | - zend_compile_expr(&format_node, args->child[0]); |
4974 | | - zend_emit_op(NULL, ZEND_ECHO, &format_node, NULL); |
4975 | | - |
4976 | | - /* Return the string length as a constant if the result is used */ |
4977 | | - result->op_type = IS_CONST; |
4978 | | - ZVAL_LONG(&result->u.constant, Z_STRLEN_P(format_string)); |
4979 | | - return SUCCESS; |
4980 | | - } |
4981 | | - } |
| 4964 | + if (args->child[0]->kind != ZEND_AST_ZVAL) { |
| 4965 | + return FAILURE; |
| 4966 | + } |
| 4967 | + zval *format_string = zend_ast_get_zval(args->child[0]); |
| 4968 | + if (Z_TYPE_P(format_string) != IS_STRING) { |
| 4969 | + return FAILURE; |
| 4970 | + } |
| 4971 | + /* Check if there are any format specifiers */ |
| 4972 | + if (!memchr(Z_STRVAL_P(format_string), '%', Z_STRLEN_P(format_string))) { |
| 4973 | + /* No format specifiers - just emit ECHO and return string length */ |
| 4974 | + znode format_node; |
| 4975 | + zend_compile_expr(&format_node, args->child[0]); |
| 4976 | + zend_emit_op(NULL, ZEND_ECHO, &format_node, NULL); |
| 4977 | + |
| 4978 | + /* Return the string length as a constant if the result is used */ |
| 4979 | + result->op_type = IS_CONST; |
| 4980 | + ZVAL_LONG(&result->u.constant, Z_STRLEN_P(format_string)); |
| 4981 | + return SUCCESS; |
4982 | 4982 | } |
4983 | 4983 | } |
4984 | 4984 |
|
|
0 commit comments