From 06c05aeb81536932a6b67d553d74978532e3ac2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Rodr=C3=ADguez?= Date: Sun, 13 Aug 2023 01:09:59 +0000 Subject: [PATCH 1/3] opcache: use zend_ast_size helper in zend_persist_ast --- ext/opcache/zend_persist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c index c8330c1e7905..b10e5a8046ab 100644 --- a/ext/opcache/zend_persist.c +++ b/ext/opcache/zend_persist.c @@ -188,7 +188,7 @@ static zend_ast *zend_persist_ast(zend_ast *ast) node = (zend_ast *) copy; } else { uint32_t children = zend_ast_get_num_children(ast); - node = zend_shared_memdup(ast, sizeof(zend_ast) - sizeof(zend_ast *) + sizeof(zend_ast *) * children); + node = zend_shared_memdup(ast, zend_ast_size(children)); for (i = 0; i < children; i++) { if (node->child[i]) { node->child[i] = zend_persist_ast(node->child[i]); From 8f7f4d3c9130939dd44243ce7e3fda1cdbf3f739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Rodr=C3=ADguez?= Date: Sun, 13 Aug 2023 01:12:57 +0000 Subject: [PATCH 2/3] opcache: use zend_ast_size helper in zend_persist_ast_calc --- ext/opcache/zend_persist_calc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c index dfc281eb7f6f..2d4a3c92afa2 100644 --- a/ext/opcache/zend_persist_calc.c +++ b/ext/opcache/zend_persist_calc.c @@ -87,7 +87,7 @@ static void zend_persist_ast_calc(zend_ast *ast) } } else { uint32_t children = zend_ast_get_num_children(ast); - ADD_SIZE(sizeof(zend_ast) - sizeof(zend_ast *) + sizeof(zend_ast *) * children); + ADD_SIZE(zend_ast_size(children)); for (i = 0; i < children; i++) { if (ast->child[i]) { zend_persist_ast_calc(ast->child[i]); From f06c283b20dd46f295c4ddb063e77260b4e8608f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Rodr=C3=ADguez?= Date: Sun, 13 Aug 2023 02:24:57 +0000 Subject: [PATCH 3/3] Zend: fix zend_ast_size definition It is better not to use sizeof(struct_with_flexible_array) and instead rely on offsetof(type, member) like most other similar wrappers do. --- Zend/zend_ast.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/zend_ast.h b/Zend/zend_ast.h index 0bbb3a820c29..4c1a87e288a7 100644 --- a/Zend/zend_ast.h +++ b/Zend/zend_ast.h @@ -313,7 +313,7 @@ typedef void (*zend_ast_apply_func)(zend_ast **ast_ptr, void *context); ZEND_API void zend_ast_apply(zend_ast *ast, zend_ast_apply_func fn, void *context); static zend_always_inline size_t zend_ast_size(uint32_t children) { - return sizeof(zend_ast) - sizeof(zend_ast *) + sizeof(zend_ast *) * children; + return XtOffsetOf(zend_ast, child) + (sizeof(zend_ast *) * children); } static zend_always_inline bool zend_ast_is_special(zend_ast *ast) {