Description
Class zend_object
is defined as a flexible array of length 1. The flexible array defined with size 1 and 0 is not the standard behavior. It is suggested to use the unsized definition (https://people.kernel.org/kees/bounded-flexible-arrays-in-c). Besides, not all its subclasses will use the array field properties_table
of the zend_object
class. If I understand the code correctly, when the properties_table[0]
field is not used, it will store a ZVAL_UNDEF zval indicating the end of the iteration. Whereas when the properties_table[0]
field is used, the flags and array length are checked first before accessing the data in the array.
If the properties_table[0]
field is not used in these sub-classes, will it be better to replace the zend_object
in these classes with only the header part of zend_object
?
i.e. (as suggested in case 2 of https://lpc.events/event/18/contributions/1722/attachments/1591/3303/Wfamnae_lpceu2024.pdf)
We can define another struct with only the header part (let's name it zend_object_header_part
), but leave the zend_object
struct with both the header and the flexible array part.
When only the header is needed, we can use the zend_object_header_part
(e.g. in the class inheritance), whereas for those requiring the array part, or using the object through a zend_object
pointer, we can still use the full definition.
Usages of zend_object
in the middle of other structs whose array field is potentially never used through the composite struct:
-
php-src/Zend/zend_generators.h
Lines 58 to 59 in c2fddac
-
php-src/Zend/zend_interfaces.c
Lines 490 to 491 in c2fddac
-
Lines 31 to 32 in c2fddac
-
Lines 102 to 104 in c2fddac
-
Lines 64 to 65 in c2fddac
-
php-src/ext/opcache/jit/zend_jit_ir.c
Lines 8451 to 8452 in c2fddac
-
php-src/ext/com_dotnet/com_saproxy.c
Lines 35 to 36 in c2fddac
-
php-src/ext/com_dotnet/php_com_dotnet_internal.h
Lines 28 to 29 in c2fddac
-
php-src/ext/com_dotnet/com_persist.c
Lines 278 to 279 in c2fddac
-
Lines 169 to 170 in c2fddac
-
Lines 191 to 192 in c2fddac
-
Lines 199 to 200 in c2fddac
-
php-src/ext/pdo/php_pdo_driver.h
Lines 645 to 646 in c2fddac
-
Lines 24 to 25 in c2fddac
-
php-src/ext/intl/normalizer/normalizer_class.h
Lines 25 to 26 in c2fddac
-
php-src/ext/intl/locale/locale_class.h
Lines 25 to 26 in c2fddac
report ids: 250106-1639:1-6,8-17 (16 reports in total)