Skip to content

fix: add null check, fix progress value and destructor order in devicemanager - #877

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

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

Conversation

@add-uos

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

Copy link
Copy Markdown
Contributor

fix: add null check, fix progress value and destructor order in devicemanager

  1. Add null check after dynamic_cast<DStyle*> in DriverHeaderView::sectionSizeHint to prevent SIGSEGV in non-DStyle environments
  2. Remove erroneous * 10 multiplication on progress value in setBackingUpDriverUI so progress bar shows correct percentage
  3. Null out layout member pointers after delete in hideAll() to prevent dangling pointers
  4. Reorder destructor to delete child layout before parent and unify on DELETE_PTR to prevent use-after-free

Log: driver backup progress bar now shows correct percentage; app no longer crashes on exit

Influence:

  1. Verify driver backup progress bar displays 0-100% correctly
  2. Verify app exits cleanly after switching between detect/download/install/backup UI states
  3. Verify header column width renders correctly in normal DStyle environment

fix: 修复设备管理器空指针崩溃、进度值越界及析构顺序错误

  1. 在 DriverHeaderView::sectionSizeHint 中为 dynamic_cast<DStyle*> 添加判空保护,防止非 DStyle 环境下段错误
  2. 移除 setBackingUpDriverUI 中对进度值错误的 ×10 乘法,使进度条显示正确百分比
  3. 在 hideAll() 中 delete 布局后立即将成员指针置空,防止悬空指针
  4. 调整析构函数删除顺序,子布局先于父布局释放,并统一使用 DELETE_PTR,防止 use-after-free

Log: 驱动备份进度条现在显示正确百分比;应用退出时不再崩溃

Influence:

  1. 验证驱动备份进度条正确显示 0-100%
  2. 验证在检测/下载/安装/备份 UI 状态间反复切换后应用正常退出
  3. 验证正常 DStyle 环境下表头列宽渲染正常

Summary by Sourcery

Harden device-manager UI lifecycle handling and correct driver backup progress reporting.

Bug Fixes:

  • Prevent crashes when the application runs without a DStyle and during device-manager UI teardown.
  • Correct the driver backup progress bar to display percentage values accurately.

Enhancements:

  • Improve device-manager layout lifecycle management by clearing deleted layout references and consistently releasing child layouts before their parents.

@sourcery-ai

sourcery-ai Bot commented Oct 23, 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 3 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 23, 2026

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

Reviewer's Guide

The PR prevents non-DStyle header-rendering crashes, makes driver-backup progress display the intended 0–100% value, and improves layout lifecycle safety by clearing rebuilt-layout pointers and deleting child layouts before their parents.

Sequence diagram for safe driver backup progress updates

sequenceDiagram
    participant Backup as DriverBackup
    participant Widget as DetectedStatusWidget
    participant Progress as QProgressBar
    Backup->>Widget: setBackingUpDriverUI(progressValue, ...)
    Widget->>Progress: setValue(progressValue)
    Note over Progress: Displays the intended 0-100% value
Loading

Flow diagram for safe layout rebuilding in hideAll

flowchart TD
    A["hideAll()"] --> B["delete this.layout()"]
    B --> C[Clear layout member pointers]
    C --> D[Create replacement layouts]
    D --> E[Rebuild UI safely]
Loading

File-Level Changes

Change Details Files
Harden header sizing when the application is not using DStyle.
  • Check the dynamic_cast result before accessing DStyle metrics.
  • Log a warning and return a safe fallback when DStyle is unavailable.
deepin-devicemanager/src/Widget/drivertableview.cpp
Correct backup progress reporting and reset layout ownership after rebuilding the UI.
  • Pass the progress value directly to the progress bar instead of multiplying it by 10.
  • Clear layout member pointers after deleting the widget layout before allocating replacement layouts.
deepin-devicemanager/src/Widget/DetectedStatusWidget.cpp
Make widget destruction safe by deleting layouts in dependency order with consistent pointer cleanup.
  • Delete the child label layout explicitly before the parent-related layouts.
  • Replace deferred deletion and manual nulling with DELETE_PTR cleanup.
deepin-devicemanager/src/Widget/DetectedStatusWidget.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

lzwind
lzwind previously approved these changes Oct 26, 2026

@lzwind lzwind left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要处理开源许可时间

…emanager

1. Add null check after dynamic_cast<DStyle*> in DriverHeaderView::sectionSizeHint to prevent SIGSEGV in non-DStyle environments
2. Remove erroneous * 10 multiplication on progress value in setBackingUpDriverUI so progress bar shows correct percentage
3. Null out layout member pointers after delete in hideAll() to prevent dangling pointers
4. Reorder destructor to delete child layout before parent and unify on DELETE_PTR to prevent use-after-free

Log: driver backup progress bar now shows correct percentage; app no longer crashes on exit

Influence:
1. Verify driver backup progress bar displays 0-100% correctly
2. Verify app exits cleanly after switching between detect/download/install/backup UI states
3. Verify header column width renders correctly in normal DStyle environment

fix: 修复设备管理器空指针崩溃、进度值越界及析构顺序错误

1. 在 DriverHeaderView::sectionSizeHint 中为 dynamic_cast<DStyle*> 添加判空保护,防止非 DStyle 环境下段错误
2. 移除 setBackingUpDriverUI 中对进度值错误的 ×10 乘法,使进度条显示正确百分比
3. 在 hideAll() 中 delete 布局后立即将成员指针置空,防止悬空指针
4. 调整析构函数删除顺序,子布局先于父布局释放,并统一使用 DELETE_PTR,防止 use-after-free

Log: 驱动备份进度条现在显示正确百分比;应用退出时不再崩溃

Influence:
1. 验证驱动备份进度条正确显示 0-100%
2. 验证在检测/下载/安装/备份 UI 状态间反复切换后应用正常退出
3. 验证正常 DStyle 环境下表头列宽渲染正常
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交是 devicemanager 的 bug 修复,包含三处合理改动:统一析构函数中使用 DELETE_PTR 宏的释放顺序、修正进度条进度值被错误放大 10 倍的问题、在 hideAll 中重建布局前将指针置空以避免悬空指针、并为 DStyle 动态转换增加空指针保护。 四维度均无明显问题,无安全漏洞,代码质量良好。

🔍 详细分析

1. 语法逻辑 ✅

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

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

建议: []


2. 代码质量 ✅

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

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

建议: []


3. 代码性能 ✅

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

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

建议: []


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例

// 当前实现已正确,无需额外修复。建议保持以下防御性写法:
// 1. dynamic_cast 后做空指针检查
DStyle *style = dynamic_cast<DStyle *>(DApplication::style());
if (!style) {
    qCWarning(appLog) << "Failed to get DStyle";
    return 0;
}
// 2. 重建布局前先置空旧指针,避免悬空指针
delete this->layout();
mp_HLayoutTotal = nullptr;
mp_HLayoutButton = nullptr;
mp_VLayoutLabel = nullptr;
mp_HLayoutLabel = nullptr;
mp_HLayoutTotal = new QHBoxLayout();

本报告由 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 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit 54e136b into linuxdeepin:master Oct 26, 2026
15 of 17 checks passed
deepin-bot Bot pushed a commit that referenced this pull request Oct 26, 2026
…emantics

The * 10 progress scaling defect in setBackingUpDriverUI was fixed on
master (PR #877), so SetBackingUpDriverUI_Called_ProgressScaledByTen
asserting the buggy value 50 now fails. Rename it to
SetBackingUpDriverUI_Called_ProgressUsesValueAsIs and expect the value
written as-is (5). Also refresh stale comments about the unchecked
dynamic_cast<DStyle*> now that sectionSizeHint has a null guard.

Verified against current master: 136/136 cases pass (36+53+47) and the
DetectedStatusWidget suite now exits cleanly.
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