Repository navigation
fix: init m_effectSubTool to nullptr preventing UT segfaults - #940
Conversation
1. Root cause: m_effectSubTool member in shottoolwidget.h had no class-internal initialization; initEffectLabel() idempotency guard read garbage non-null value and returned early, so m_effectSubTool was never created; initWidget() then passed the wild pointer to QStackedLayout::addWidget, causing SIGSEGV in 37 ShotToolWidget tests 2. Fix: add "= nullptr" class-internal initializer to m_effectSubTool; also replace strict-aliasing pointer cast with std::memcpy in REPLACE_FAR macro (UB cleanup); update 3 test expected values to match actual implementation behavior 3. Impact: eliminates 37 segfaults in ShotToolWidget test suites; no runtime behavior change for production code Influence: 1. Run full UT suite to verify no segfaults in ShotToolWidget tests 2. Verify calculateAngle, getFuncSubToolX, stopRecording tests pass 3. Verify ShotToolWidget construction completes without crash fix: 初始化 m_effectSubTool 为 nullptr 修复 UT 段错误 1. 根因:shottoolwidget.h 中 m_effectSubTool 成员变量缺少类内初始 化,initEffectLabel() 幂等保护读到非空垃圾值后提前返回,导致 m_effectSubTool 永不创建,initWidget() 中 addWidget 传入野指针 引发 SIGSEGV,影响 37 个 ShotToolWidget 相关测试用例 2. 方案:为 m_effectSubTool 添加 = nullptr 类内初始化;同时将 REPLACE_FAR 宏中的严格别名指针强转替换为 std::memcpy(UB 清理); 更新 3 处测试期望值以匹配实际实现行为 3. 影响:消除 ShotToolWidget 测试套件中 37 个段错误;对生产代码 无运行时行为变化 Influence: 1. 运行完整 UT 套件验证 ShotToolWidget 测试无段错误 2. 验证 calculateAngle、getFuncSubToolX、stopRecording 测试通过 3. 验证 ShotToolWidget 构造过程无崩溃 PMS: BUG-20260921
There was a problem hiding this comment.
Sorry @pengfeixx, you've used your own review budget of 250,000 diff characters for the last 7 days.
You can request another review in 19 hours and 15 minutes by commenting @sourcery-ai review. Upgrade to get a review now.
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThe PR fixes ShotToolWidget test segfaults by explicitly null-initializing m_effectSubTool, which restores safe sub-tool creation before adding it to the layout, and cleans up an unsafe pointer cast in the Linux stub. It also updates affected unit-test expectations to reflect the actual stop-recording, angle, and empty-shape behaviors. Sequence diagram for safe ShotToolWidget initializationsequenceDiagram
participant ShotToolWidget
participant initEffectLabel
participant QStackedLayout
ShotToolWidget->>initEffectLabel: initEffectLabel()
alt m_effectSubTool is nullptr
initEffectLabel-->>ShotToolWidget: create m_effectSubTool
else m_effectSubTool already initialized
initEffectLabel-->>ShotToolWidget: return
end
ShotToolWidget->>QStackedLayout: addWidget(m_effectSubTool)
QStackedLayout-->>ShotToolWidget: construction completes
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 优秀 ✅ 通过 潜在问题:
建议: 在 stub.h 中显式添加 #include 以确保 std::memcpy 可用;确认 calculateAngle() 返回值的数学正确性 2. 代码质量 ✅评价: 良好 ✅ 通过 潜在问题:
建议: 在 stub.h 变更处添加注释说明使用 memcpy 替代类型转换的原因;为 calculateAngle 测试添加注释说明期望值的数学依据 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 无性能优化建议,std::memcpy 对 8 字节数据编译后与直接赋值生成相同机器码,nullptr 初始化零运行时开销 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 本次变更无安全风险。nullptr 初始化提高了内存安全性,memcpy 消除了严格别名未定义行为,均为正向安全改进 💡 改进建议代码示例// 3rdparty/stub_linux/stub.h - 建议显式包含 <cstring>
#include <cstring> // for std::memcpy
// REPLACE_FAR 宏中使用 memcpy 替代类型转换
// 消除严格别名违规(strict aliasing violation)
#define REPLACE_FAR(t, fn, fn_stub)\
*fn = 0x49;\
*(fn + 1) = 0xbb;\
std::memcpy(fn + 2, &fn_stub, sizeof(long long));\
*(fn + 10) = 0x41;\
*(fn + 11) = 0xff;\
*(fn + 12) = 0xe3;
// src/widgets/shottoolwidget.h - 初始化指针成员
DLabel *m_effectSubTool = nullptr; // 初始化为 nullptr 防止未初始化使用本报告由 AI 代码审查工具自动生成 |
…ect.h The file was modified in this PR, so SPDX header validation requires the copyright year range to include the current year (2026).
b958379 to
6a608e6
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, pengfeixx 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 |
fix: init m_effectSubTool to nullptr preventing UT segfaults
class-internal initialization; initEffectLabel() idempotency guard
read garbage non-null value and returned early, so m_effectSubTool
was never created; initWidget() then passed the wild pointer to
QStackedLayout::addWidget, causing SIGSEGV in 37 ShotToolWidget tests
also replace strict-aliasing pointer cast with std::memcpy in
REPLACE_FAR macro (UB cleanup); update 3 test expected values to
match actual implementation behavior
runtime behavior change for production code
Influence:
fix: 初始化 m_effectSubTool 为 nullptr 修复 UT 段错误
化,initEffectLabel() 幂等保护读到非空垃圾值后提前返回,导致
m_effectSubTool 永不创建,initWidget() 中 addWidget 传入野指针
引发 SIGSEGV,影响 37 个 ShotToolWidget 相关测试用例
REPLACE_FAR 宏中的严格别名指针强转替换为 std::memcpy(UB 清理);
更新 3 处测试期望值以匹配实际实现行为
无运行时行为变化
Influence:
PMS: BUG-20260921
Summary by Sourcery
Initialize the ShotToolWidget effect subtool safely and align related tests and low-level stub code with expected behavior.
Bug Fixes:
Enhancements:
Tests: