-
Notifications
You must be signed in to change notification settings - Fork 8k
Zend: fix gcc12 -Warray-bounds warning #8476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
gcc12 complains:
zend_API.c:2782:49: warning: array subscript ‘zend_function {aka union _zend_function}[0]’ is partly outside array bounds of ‘unsigned char[120]’ [-Warray-bounds]
zend_API.c:2772:32: note: object of size 120 allocated by ‘malloc’
reg_function = malloc(sizeof(zend_internal_function));
The warning is correct, reg_function allocation size is too small for its type,
allocate sizeof(zend_function) instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, this looks right, thank you! Shouldn't this be fixed for PHP-8.0+, though?
| lowercase_name = zend_new_interned_string(lowercase_name); | ||
| reg_function = malloc(sizeof(zend_internal_function)); | ||
| memcpy(reg_function, &function, sizeof(zend_internal_function)); | ||
| reg_function = calloc(1, sizeof(zend_function)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That calloc() appears unnecessary, since we're overwriting the memory in the next statement anyway.
|
@cmb69 the allocation has the right size, but technically the proper target is |
|
Holy hack, Batman! I see that this is not a bug in php-src. But if we always treat |
|
I suppose to avoid a couple explicit casts back to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the discussion so far, this doesn't look like the proper fix. Either there is a simple way to avoid the compiler warning, or maybe we should see how changing reg_function to be of type zend_internal_function may work out.
|
There has not been any recent activity in this PR. It will automatically be closed in 7 days if no further action is taken. |
gcc12 complains:
zend_API.c:2782:49: warning: array subscript ‘zend_function {aka union _zend_function}[0]’ is partly outside array bounds of ‘unsigned char[120]’ [-Warray-bounds]
zend_API.c:2772:32: note: object of size 120 allocated by ‘malloc’
reg_function = malloc(sizeof(zend_internal_function));
The warning is correct, reg_function allocation size is too small for its type,
allocate sizeof(zend_function) instead.