Skip to content

fix: add null check before clearWidgets in updateTable - #868

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

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:agent/bug/8a228fba5afe

Conversation

@add-uos

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

Copy link
Copy Markdown
Contributor

fix: add null check before clearWidgets in updateTable

  1. Root cause: mp_PageInfo is initialized to nullptr in constructor
    and only assigned later in updateTable, but clearWidgets() is called
    unconditionally at function entry before any assignment
  2. Fix: add null pointer check before calling clearWidgets() to prevent
    segfault on first invocation when mp_PageInfo is still nullptr
  3. Impact: prevents crash on first call to updateTable, no behavior
    change for subsequent calls where mp_PageInfo is already assigned

Influence:

  1. Test updateTable first invocation with empty device list
  2. Test updateTable with single device and multiple devices
  3. Verify no regression on existing device info display scenarios

fix: 修复updateTable中clearWidgets空指针解引用崩溃

  1. 根因:mp_PageInfo在构造函数中初始化为nullptr,仅在updateTable
    内部条件分支中赋值,但clearWidgets()在函数入口无条件调用
    先于所有赋值逻辑执行
  2. 方案:在调用clearWidgets()前增加空指针检查,首次调用时
    mp_PageInfo为nullptr则跳过避免段错误
  3. 影响:防止首次调用updateTable时崩溃,对后续调用无行为变化

Influence:

  1. 测试首次调用updateTable传入空设备列表
  2. 测试单个设备和多设备场景的updateTable调用
  3. 验证现有设备信息显示场景无回归

PMS: BUG-DM-DEF-002

Summary by Sourcery

Bug Fixes:

  • Prevent the first updateTable invocation from crashing when page information has not yet been initialized.

@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 7 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 22, 2026

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

Reviewer's Guide

Prevents a first-call null-pointer dereference in updateTable by conditionally clearing widgets, while leaving subsequent update behavior unchanged.

Sequence diagram for safe first updateTable invocation

sequenceDiagram
    participant Caller
    participant PageInfoWidget
    participant PageInfo

    Caller->>PageInfoWidget: updateTable(itemStr, lst)
    alt mp_PageInfo exists
        PageInfoWidget->>PageInfo: clearWidgets()
    else mp_PageInfo is nullptr
        PageInfoWidget->>PageInfoWidget: Continue without clearWidgets()
    end
    PageInfoWidget->>PageInfoWidget: Update device information
Loading

File-Level Changes

Change Details Files
Guard widget cleanup against an uninitialized page-info pointer during table updates.
  • Check mp_PageInfo before invoking clearWidgets().
  • Preserve existing cleanup behavior once mp_PageInfo has been initialized.
deepin-devicemanager/src/Page/PageInfoWidget.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: mp_PageInfo is initialized to nullptr in constructor
   and only assigned later in updateTable, but clearWidgets() is called
   unconditionally at function entry before any assignment
2. Fix: add null pointer check before calling clearWidgets() to prevent
   segfault on first invocation when mp_PageInfo is still nullptr
3. Update SPDX copyright year from 2022 to 2022-2026 to reflect
   modification year per CI copyright header requirements
4. Impact: prevents crash on first call to updateTable, no behavior
   change for subsequent calls where mp_PageInfo is already assigned

Influence:
1. Test updateTable first invocation with empty device list
2. Test updateTable with single device and multiple devices
3. Verify no regression on existing device info display scenarios

fix: 修复updateTable中clearWidgets空指针解引用崩溃

1. 根因:mp_PageInfo在构造函数中初始化为nullptr,仅在updateTable
   内部条件分支中赋值,但clearWidgets()在函数入口无条件调用
   先于所有赋值逻辑执行
2. 方案:在调用clearWidgets()前增加空指针检查,首次调用时
   mp_PageInfo为nullptr则跳过避免段错误
3. 更新SPDX版权年份从2022改为2022-2026以符合CI版权头规范
4. 影响:防止首次调用updateTable时崩溃,对后续调用无行为变化

Influence:
1. 测试首次调用updateTable传入空设备列表
2. 测试单个设备和多设备场景的updateTable调用
3. 验证现有设备信息显示场景无回归

PMS: BUG-DM-DEF-002
@add-uos
add-uos force-pushed the agent/bug/8a228fba5afe branch from f10a20d to 1fcc282 Compare October 26, 2026 07:02
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为空指针防御性检查修复,在 PageInfoWidget::updateTable 函数中调用 clearWidgets 前增加 mp_PageInfo 非空判断,有效防止潜在的空指针解引用崩溃。代码变更范围小、目的明确、实现正确,无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

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

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

建议: []


2. 代码质量 ✅

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

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

建议: []


3. 代码性能 ✅

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

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

建议: []


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: ['建议在 PageInfoWidget 类的其他方法中统一排查 mp_PageInfo 指针的使用,确保所有解引用处均有空指针保护,形成一致的防御性编程风格。']


💡 改进建议代码示例

// 当前实现已是正确的修复方式,无需额外修改:
void PageInfoWidget::updateTable(const QString &itemStr, const QList<DeviceBaseInfo *> &lst)
{
    qCDebug(appLog) << "Updating table with" << lst.size() << "devices, type:" << itemStr;
    if (mp_PageInfo) {
        mp_PageInfo->clearWidgets();
    }

    // 设备个数为0,是概况界面
    if (lst.size() == 0) {
        // ...
    }
}

本报告由 AI 代码审查工具自动生成

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, lzwind

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

@add-uos

add-uos commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot
deepin-bot Bot merged commit 43f4610 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.

3 participants