Skip to content

fix: add null check for PageSingleInfo cast in RichTextDelegate - #870

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

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

Conversation

@add-uos

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

Copy link
Copy Markdown
Contributor

fix: add null check for PageSingleInfo cast in RichTextDelegate

  1. RichTextDelegate::paint dereferences dynamic_cast result without
    null check when parent is not PageSingleInfo
  2. Add null pointer check before calling setRowHeight to prevent crash
  3. No behavior change when parent is PageSingleInfo, only skips
    setRowHeight when parent is other type like PageTableWidget

Influence:

  1. Test RichTextDelegate with PageSingleInfo parent and multi-line text
  2. Test RichTextDelegate with PageTableWidget parent and multi-line text
  3. Verify no crash and text rendering is correct in both cases

fix: RichTextDelegate::paint 增加空指针检查防止崩溃

  1. RichTextDelegate::paint 在 parent 非 PageSingleInfo 时
    dynamic_cast 返回空指针后直接解引用导致崩溃
  2. 增加 dynamic_cast 结果空指针检查后再调用 setRowHeight
  3. parent 为 PageSingleInfo 时行为不变,为其他类型时跳过
    setRowHeight 调用不影响文本绘制

Influence:

  1. 测试 parent 为 PageSingleInfo 时多行文本绘制正常
  2. 测试 parent 为 PageTableWidget 时多行文本不崩溃
  3. 验证两种场景下文本渲染结果正确

Summary by Sourcery

Bug Fixes:

  • Prevent RichTextDelegate from crashing when its parent is not a PageSingleInfo by checking the cast result before updating row height.

@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 5 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

RichTextDelegate::paint now safely handles non-PageSingleInfo parents by conditionally updating row height while preserving existing rendering and PageSingleInfo behavior.

Sequence diagram for safe RichTextDelegate painting

sequenceDiagram
    participant View as View
    participant Delegate as RichTextDelegate
    participant Parent as ParentWidget
    participant PageInfo as PageSingleInfo
    participant Painter as QPainter

    View->>Delegate: paint(painter, option, index)
    Delegate->>Parent: dynamic_cast<PageSingleInfo*>()
    alt parent is PageSingleInfo
        Parent-->>Delegate: PageSingleInfo*
        Delegate->>PageInfo: setRowHeight(index.row(), height + 6)
    else parent is another widget
        Parent-->>Delegate: nullptr
    end
    Delegate->>Painter: draw text document
Loading

File-Level Changes

Change Details Files
Guard the PageSingleInfo downcast before updating row height, preventing crashes for delegates attached to other parent widget types.
  • Store the dynamic_cast result in a PageSingleInfo pointer.
  • Call setRowHeight only when the cast succeeds.
  • Leave text document painting unchanged for all parent types.
deepin-devicemanager/src/Widget/RichTextDelegate.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. RichTextDelegate::paint dereferences dynamic_cast result without
   null check when parent is not PageSingleInfo
2. Add null pointer check before calling setRowHeight to prevent crash
3. No behavior change when parent is PageSingleInfo, only skips
   setRowHeight when parent is other type like PageTableWidget
4. Update SPDX copyright year from 2022 to 2022-2026 for CI compliance

Influence:
1. Test RichTextDelegate with PageSingleInfo parent and multi-line text
2. Test RichTextDelegate with PageTableWidget parent and multi-line text
3. Verify no crash and text rendering is correct in both cases

fix: RichTextDelegate::paint 增加空指针检查防止崩溃

1. RichTextDelegate::paint 在 parent 非 PageSingleInfo 时
   dynamic_cast 返回空指针后直接解引用导致崩溃
2. 增加 dynamic_cast 结果空指针检查后再调用 setRowHeight
3. parent 为 PageSingleInfo 时行为不变,为其他类型时跳过
   setRowHeight 调用不影响文本绘制
4. 更新 SPDX 版权年份从 2022 为 2022-2026 以满足 CI 检查

Influence:
1. 测试 parent 为 PageSingleInfo 时多行文本绘制正常
2. 测试 parent 为 PageTableWidget 时多行文本不崩溃
3. 验证两种场景下文本渲染结果正确
@add-uos
add-uos force-pushed the agent/pms-bug-bot/266b66d9b98b branch from 53fac78 to 3aa0450 Compare October 26, 2026 03:09
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交修复了 RichTextDelegate::paint 函数中 dynamic_cast 转换后未做空指针检查导致的潜在崩溃问题。 通过引入局部变量 pageInfo 并添加 null 检查,在 dynamic_cast 返回 nullptr 时跳过 setRowHeight 调用, 有效提升了代码健壮性。变更范围小、目标明确,四维度均无问题。同时更新了 SPDX 版权年份,合规合理。

🔍 详细分析

1. 语法逻辑 ✅

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

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

建议: []


2. 代码质量 ✅

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

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

建议: []


3. 代码性能 ✅

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

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

建议: []


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例

// 当前代码已是最佳实践,无需额外修改: PageSingleInfo *pageInfo = dynamic_cast<PageSingleInfo *>(this->parent()); if (pageInfo) {
    pageInfo->setRowHeight(index.row(), textDoc.size().toSize().height() + 6);
}

本报告由 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 8fe261f into linuxdeepin:master Oct 26, 2026
15 of 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