Skip to content

Commit 2196e22

Browse files
authored
Use zend_ast_size consistenly (#11955)
* opcache: use zend_ast_size helper in zend_persist_ast * opcache: use zend_ast_size helper in zend_persist_ast_calc * 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.
1 parent e56ed6e commit 2196e22

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

Zend/zend_ast.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ typedef void (*zend_ast_apply_func)(zend_ast **ast_ptr, void *context);
313313
ZEND_API void zend_ast_apply(zend_ast *ast, zend_ast_apply_func fn, void *context);
314314

315315
static zend_always_inline size_t zend_ast_size(uint32_t children) {
316-
return sizeof(zend_ast) - sizeof(zend_ast *) + sizeof(zend_ast *) * children;
316+
return XtOffsetOf(zend_ast, child) + (sizeof(zend_ast *) * children);
317317
}
318318

319319
static zend_always_inline bool zend_ast_is_special(zend_ast *ast) {

ext/opcache/zend_persist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static zend_ast *zend_persist_ast(zend_ast *ast)
188188
node = (zend_ast *) copy;
189189
} else {
190190
uint32_t children = zend_ast_get_num_children(ast);
191-
node = zend_shared_memdup(ast, sizeof(zend_ast) - sizeof(zend_ast *) + sizeof(zend_ast *) * children);
191+
node = zend_shared_memdup(ast, zend_ast_size(children));
192192
for (i = 0; i < children; i++) {
193193
if (node->child[i]) {
194194
node->child[i] = zend_persist_ast(node->child[i]);

ext/opcache/zend_persist_calc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static void zend_persist_ast_calc(zend_ast *ast)
8787
}
8888
} else {
8989
uint32_t children = zend_ast_get_num_children(ast);
90-
ADD_SIZE(sizeof(zend_ast) - sizeof(zend_ast *) + sizeof(zend_ast *) * children);
90+
ADD_SIZE(zend_ast_size(children));
9191
for (i = 0; i < children; i++) {
9292
if (ast->child[i]) {
9393
zend_persist_ast_calc(ast->child[i]);

0 commit comments

Comments
 (0)