Repository navigation
fix(daemon): suppress GCC 16 -Warray-bounds false positive - #113
Merged
Merged
Conversation
1. Wrap the ControlHeader memcpy in DdeSeatdControl with a local GCC -Warray-bounds suppression and document why the copy is in bounds. 2. The while loop above already guarantees the buffer holds at least sizeof(ControlHeader) bytes, so the copy is in bounds. GCC 15/16 cannot relate QByteArray::size() to the pointer returned by constData(), which may be the 1-byte static QByteArray::_empty. 3. No wire format, byte order or runtime behaviour change. Log: No user-facing changes Influence: 1. Build ddm on Arch Linux (GCC 16, -Werror) and confirm it passes. 2. Check that DdeSeatdControl.cpp:391 no longer emits array-bounds. 3. Verify dde-seatd control messages are still received correctly. fix(daemon): 抑制 GCC 16 对 constData() 的 -Warray-bounds 误报 1. 在 DdeSeatdControl 中对 ControlHeader 的 memcpy 局部关闭 GCC 的 -Warray-bounds 告警,并注明该拷贝在界内的原因。 2. 上方 while 循环已保证缓冲区长度不小于 sizeof(ControlHeader); GCC 15/16 无法把 QByteArray::size() 与 constData() 返回的指针 关联,后者可能指向 1 字节静态 QByteArray::_empty,故为误报。 3. 不改变线格式、字节序与运行时行为。 Log: 无用户可见变化 Influence: 1. 在 Arch Linux(GCC 16、-Werror)下构建 ddm,确认通过。 2. 确认 DdeSeatdControl.cpp:391 不再报 array-bounds。 3. 验证 dde-seatd 控制消息仍能正常收发。 Multica Issue: WM-566
|
Skipping CI for Draft Pull Request. |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThe PR fixes Arch/GCC 15–16 build failures by locally suppressing an array-bounds false positive caused by GCC’s inability to connect QByteArray::size() with constData(), while retaining the existing size guard and unchanged safe memcpy behavior. Flow diagram for guarded event-buffer header copyflowchart TD
A[m_eventBuffer.append] --> B{m_eventBuffer.size >= sizeof ControlHeader}
B -- No --> C[Exit loop]
B -- Yes --> D[QT_WARNING_PUSH]
D --> E[QT_WARNING_DISABLE_GCC -Warray-bounds]
E --> F[memcpy from m_eventBuffer.constData to header]
F --> G[QT_WARNING_POP]
G --> H[Process ControlHeader]
H --> B
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
zccrs
approved these changes
Oct 10, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: deepin-wm, zccrs The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
zccrs
marked this pull request as ready for review
October 10, 2026 02:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
ddm 的
Build ddm on Arch Linux工作流在master基线上因-Werror=array-bounds中断,导致所有 ddm PR 的该检查都是红的。触发 run:https://github.com/linuxdeepin/ddm/actions/runs/37735447997这是
archlinux:latest滚动到 GCC 16 之后暴露的既有问题,与任何 PR 的改动都无关(最初触发它的 PR #112 只改了 2 个 workflow 文件的on:触发条件)。根因
QByteArray::constData()在空数据时可能返回 1 字节的静态QByteArray::_empty(const char[1])。GCC 15/16 的-Warray-bounds无法把size()的返回值与constData()返回的指针关联起来,于是把「源码来自 1 字节静态对象」这条不可达路径当成可能路径,对 4 字节的memcpy报错。原代码并没有越界:
src/daemon/DdeSeatdControl.cpp:389的循环条件已经是while (m_eventBuffer.size() >= static_cast<int>(sizeof(ControlHeader))),进入循环体时缓冲区至少有sizeof(ControlHeader)= 4 字节,第 391 行的memcpy是安全的。改动内容
src/daemon/DdeSeatdControl.cpp一处,1 文件 / +7 行:memcpy局部使用QT_WARNING_PUSH/QT_WARNING_DISABLE_GCC("-Warray-bounds")/QT_WARNING_POP,只关闭 GCC 的这一次误报;while已保证长度」以及「GCC 15/16 对QByteArray::constData()的误报成因」,避免后来人误以为这里本来就可能越界。为什么这么改
QT_WARNING_DISABLE_GCC只对 GCC 生效,不会掩盖 clang 的真实告警。验证
archlinux:latest容器(GCC 16.2.1 / Qt 6.12.0,编译参数与 workflow 完全一致-DCMAKE_CXX_FLAGS="-Wall -Wextra -Werror")中先复现同一报错,应用本改动后完整构建 53/53 个 target 通过、链接产出src/daemon/ddm、退出码 0。关联
Summary by Sourcery
Prevent GCC 15/16 false-positive array-bounds warnings from failing daemon builds without changing runtime behavior.
Bug Fixes:
-Warray-boundsdiagnostic that breaks Arch Linux daemon builds.Enhancements: