diff --git a/Zend/zend_ast.h b/Zend/zend_ast.h index 0bbb3a820c291..4c1a87e288a73 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) { diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c index c8330c1e79057..b10e5a8046ab1 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]); diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c index dfc281eb7f6f7..2d4a3c92afa29 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]);