Skip to content

Commit 2ae379b

Browse files
code cleanup from pr review
1 parent 3626cc0 commit 2ae379b

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

Zend/zend_compile.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "zend_API.h"
2929
#include "zend_exceptions.h"
3030
#include "zend_interfaces.h"
31+
#include "zend_types.h"
3132
#include "zend_virtual_cwd.h"
3233
#include "zend_multibyte.h"
3334
#include "zend_language_scanner.h"
@@ -4960,25 +4961,24 @@ static zend_result zend_compile_func_printf(znode *result, zend_ast_list *args)
49604961
* In this case, just emit ECHO and return the string length if needed. */
49614962
if (args->children == 1) {
49624963
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;
49824982
}
49834983
}
49844984

0 commit comments

Comments
 (0)