Skip to content

fix: guard null pointer and reset expand state in DetailTreeView - #865

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:agent/pms-bug-bot/3178bca11083
Oct 26, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:agent/pms-bug-bot/3178bca11083

Conversation

@add-uos

@add-uos add-uos commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

fix: guard null pointer and reset expand state in DetailTreeView

  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

Summary by Sourcery

Guard detail expansion against missing controls and reset expansion state when clearing the view.

Bug Fixes:

  • Prevent null-pointer crashes when expanding or collapsing details without an available command button.
  • Reset the expanded state when clearing the detail tree to keep state consistent with the button lifecycle.

@sourcery-ai

sourcery-ai Bot commented Oct 22, 2026

Copy link
Copy Markdown

Sorry @add-uos, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 5 days and 8 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@deepin-ci-robot

Copy link
Copy Markdown

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai

sourcery-ai Bot commented Oct 22, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Prevents 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 lifecycle

stateDiagram-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
Loading

File-Level Changes

Change Details Files
Harden expand/collapse handling against a missing command button.
  • Add an early nullptr check in the expand/collapse handler.
  • Emit a warning and skip the operation when the button is unavailable, covering signal and direct-call paths.
deepin-devicemanager/src/Widget/DetailTreeView.cpp
Keep expansion state synchronized with command-button lifecycle.
  • Reset the expansion flag after clear() deletes and nulls the command button.
  • Preserve existing behavior when the button exists.
deepin-devicemanager/src/Widget/DetailTreeView.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

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
@lzwind
lzwind force-pushed the agent/pms-bug-bot/3178bca11083 branch from 04e9048 to 87f0574 Compare October 26, 2026 02:16
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为空指针防护与展开状态重置的Bug修复,变更内容简洁、目标明确,四维度均无问题,未引入安全漏洞。null指针guard有效防止了潜在的空指针解引用崩溃,clear()中重置m_IsExpand状态避免了陈旧状态导致的逻辑错误。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 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 代码审查工具自动生成

@add-uos

add-uos commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit a90cd81 into linuxdeepin:master Oct 26, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants