PHP 8.2 build warnings: -Warray-bounds, -Wmaybe-uninitialized

未关闭
#23,633 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
62/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
c
领域
build-system

调研方向

使用 buildconf、./configure --with-pear --enable-xml 和 make -j16,并使用 GCC 12.2.0,重现该报告。检查 Zend/zend_API.c 中 zend_register_functions 附近的代码,以及 ext/opcache/jit/zend_jit_trace.c 中 zend_jit_trace 附近的代码,然后验证 PHP 8.2 源码构建能够在没有这些警告的情况下完成。

由索引模型根据 Issue 内容生成。

描述

Category: Build System Status: Needs Triage

buildconf, ./configure --with-pear --enable-xml, followed by make -j16 included the following warnings:

zend_API.c -Warray-bounds
/usr/src/php/Zend/zend_API.c: In function 'zend_register_functions':
/usr/src/php/Zend/zend_API.c:2843:49: warning: array subscript 'zend_function {aka union _zend_function}[0]' is partly outside array bounds of 'unsigned char[136]' [-Warray-bounds]
 2843 |                 uint32_t num_args = reg_function->common.num_args;
      |                                                 ^~
/usr/src/php/Zend/zend_API.c:2833:32: note: object of size 136 allocated by 'malloc'
 2833 |                 reg_function = malloc(sizeof(zend_internal_function));
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/src/php/Zend/zend_API.c:2844:33: warning: array subscript 'zend_function {aka union _zend_function}[0]' is partly outside array bounds of 'unsigned char[136]' [-Warray-bounds]
 2844 |                 if (reg_function->common.fn_flags & ZEND_ACC_VARIADIC) {
      |                                 ^~
/usr/src/php/Zend/zend_API.c:2833:32: note: object of size 136 allocated by 'malloc'
 2833 |                 reg_function = malloc(sizeof(zend_internal_function));
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/src/php/Zend/zend_API.c:2849:33: warning: array subscript 'zend_function {aka union _zend_function}[0]' is partly outside array bounds of 'unsigned char[136]' [-Warray-bounds]
 2849 |                 if (reg_function->common.arg_info && num_args) {
      |                                 ^~
/usr/src/php/Zend/zend_API.c:2833:32: note: object of size 136 allocated by 'malloc'
 2833 |                 reg_function = malloc(sizeof(zend_internal_function));
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/src/php/Zend/zend_API.c:2855:49: warning: array subscript 'zend_function {aka union _zend_function}[0]' is partly outside array bounds of 'unsigned char[136]' [-Warray-bounds]
 2855 |                                     reg_function->common.fn_flags |= ZEND_ACC_HAS_TYPE_HINTS;
      |                                                 ^~
/usr/src/php/Zend/zend_API.c:2833:32: note: object of size 136 allocated by 'malloc'
 2833 |                 reg_function = malloc(sizeof(zend_internal_function));
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/src/php/Zend/zend_API.c:2855:49: warning: array subscript 'zend_function {aka union _zend_function}[0]' is partly outside array bounds of 'unsigned char[136]' [-Warray-bounds]
 2855 |                                     reg_function->common.fn_flags |= ZEND_ACC_HAS_TYPE_HINTS;
      |                                                 ^~
/usr/src/php/Zend/zend_API.c:2833:32: note: object of size 136 allocated by 'malloc'
 2833 |                 reg_function = malloc(sizeof(zend_internal_function));
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/src/php/Zend/zend_API.c:2871:34: warning: array subscript 'zend_function {aka union _zend_function}[0]' is partly outside array bounds of 'unsigned char[136]' [-Warray-bounds]
 2871 |                     (reg_function->common.fn_flags & (ZEND_ACC_HAS_RETURN_TYPE|ZEND_ACC_HAS_TYPE_HINTS))) {
      |                                  ^~
/usr/src/php/Zend/zend_API.c:2833:32: note: object of size 136 allocated by 'malloc'
 2833 |                 reg_function = malloc(sizeof(zend_internal_function));
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/src/php/Zend/zend_API.c:2881:37: warning: array subscript 'zend_function {aka union _zend_function}[0]' is partly outside array bounds of 'unsigned char[136]' [-Warray-bounds]
 2881 |                         reg_function->common.arg_info = new_arg_info + 1;
      |                                     ^~
/usr/src/php/Zend/zend_API.c:2833:32: note: object of size 136 allocated by 'malloc'
 2833 |                 reg_function = malloc(sizeof(zend_internal_function));
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ext/opcache/jit/zend_jit_trace.c -Wmaybe-uninitialized
In file included from /usr/src/php/ext/opcache/jit/zend_jit.c:4445:
ext/opcache/jit/zend_jit_trace.c: In function 'zend_jit_trace':
ext/opcache/jit/zend_jit_trace.c:6533:86: warning: 'gen_handler' may be used uninitialized [-Wmaybe-uninitialized]
 6533 |                                                                         (gen_handler || !ra || !ra[ssa_op->op1_def]));
      |                                                                                      ^~
ext/opcache/jit/zend_jit_trace.c:4300:30: note: 'gen_handler' was declared here
 4300 |                         bool gen_handler;
      |                              ^~~~~~~~~~~

while 8.2 is security only, it should still support building from source

Built using gcc (Debian 12.2.0-14+deb12u1) 12.2.0 against latest 8.2 commit, 4fa25b04e76ccafda9a778f2ba2aaeb66fad1037

主要语言
C
星标
40.4k
派生
8.2k
平均合并
2 天 15 小时
30 天内合并 PR
103

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

php/php-src 的其他 Issue

查看 php/php-src 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。