Repository navigation
fix: guard null pointer and reset expand state in DetailTreeView - #865
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos 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 |
Reviewer's guide (collapsed on small PRs)Reviewer's GuidePrevents DetailTreeView null-pointer crashes by guarding expand/collapse operations and resets expansion state during clear(), keeping state consistent after the command button is removed without changing normal behavior. State diagram for DetailTreeView expansion lifecyclestateDiagram-v2
[*] --> Collapsed
Collapsed --> Expanded: expandCommandLinkClicked()
Expanded --> Collapsed: expandCommandLinkClicked()
Expanded --> Collapsed: clear()
Collapsed --> Cleared: clear()
Expanded --> Cleared: clear()
Cleared --> Cleared: expandCommandLinkClicked() / warning and return
Cleared --> Collapsed: setColumnAndRow() creates button
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
1. Root cause: expandCommandLinkClicked() directly calls mp_CommandBtn->setText() without null check, SIGSEGV when button is null after clear() deletes it or setColumnAndRow skips creation 2. Fix: add nullptr guard at function entry, log warning and return early when mp_CommandBtn is null; reset m_IsExpand to false in clear() after deleting button to keep state consistent with button lifecycle 3. Impact: covers all call paths (signal-triggered and direct call from PageTableWidget::expandTable), no behavior change when button exists fix: 修复DetailTreeView空指针崩溃及展开状态不一致 1. 根因:expandCommandLinkClicked()未做空指针检查直接调用 mp_CommandBtn->setText(),clear()删除按钮或setColumnAndRow 未创建按钮时导致SIGSEGV;clear()不重置m_IsExpand导致后续 调用命中展开分支解引用空指针 2. 方案:在函数入口添加nullptr防护,mp_CommandBtn为空时记录 警告日志并提前返回;在clear()中删除并置空按钮后添加 m_IsExpand=false,使展开状态与按钮生命周期保持一致 3. 影响:覆盖所有调用路径(信号触发及PageTableWidget::expandTable 直接调用),按钮存在时行为不变 PMS: BUG-bug-fix-1
04e9048 to
87f0574
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: [] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: [] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例本次变更已是良好的修复实现,无需额外改进。当前代码示例:
// clear() 方法中重置展开状态 void DetailTreeView::clear() {
// ... 已有清理逻辑 ...
if (mp_CommandBtn) {
delete mp_CommandBtn;
mp_CommandBtn = nullptr;
}
m_IsExpand = false;
}
// expandCommandLinkClicked() 方法中添加空指针防护 void DetailTreeView::expandCommandLinkClicked() {
qCInfo(appLog) << "Expand/collapse button clicked. Current state:" << m_IsExpand;
if (mp_CommandBtn == nullptr) {
qCWarning(appLog) << "Command button is null, abort expand/collapse operation";
return;
}
// 后续展开/折叠逻辑 ...
}本报告由 AI 代码审查工具自动生成 |
|
/forcemerge |
|
This pr force merged! (status: blocked) |
fix: guard null pointer and reset expand state in DetailTreeView
mp_CommandBtn->setText() without null check, SIGSEGV when button
is null after clear() deletes it or setColumnAndRow skips creation
early when mp_CommandBtn is null; reset m_IsExpand to false in
clear() after deleting button to keep state consistent with
button lifecycle
from PageTableWidget::expandTable), no behavior change when button
exists
fix: 修复DetailTreeView空指针崩溃及展开状态不一致
mp_CommandBtn->setText(),clear()删除按钮或setColumnAndRow
未创建按钮时导致SIGSEGV;clear()不重置m_IsExpand导致后续
调用命中展开分支解引用空指针
警告日志并提前返回;在clear()中删除并置空按钮后添加
m_IsExpand=false,使展开状态与按钮生命周期保持一致
直接调用),按钮存在时行为不变
PMS: BUG-bug-fix-1
Summary by Sourcery
Guard detail expansion against missing controls and reset expansion state when clearing the view.
Bug Fixes: