Skip to content

fix(dde-lowpower): fix null pointer crash when screenAt returns null … - #442

Merged
mhduiy merged 1 commit into
linuxdeepin:masterfrom
mhduiy:crash
Jul 27, 2026
Merged

fix(dde-lowpower): fix null pointer crash when screenAt returns null …#442
mhduiy merged 1 commit into
linuxdeepin:masterfrom
mhduiy:crash

Conversation

@mhduiy

@mhduiy mhduiy commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

…on Wayland

  1. Added null check for QScreen pointer returned by screenAt(QCursor::pos())
  2. Fallback to primaryScreen() when screenAt fails on Wayland
  3. Early return if no screen available at all
  4. Prevents SIGSEGV when QCursor::pos() returns invalid position

Log: Fix dde-lowpower crash on Wayland due to null screen pointer
Influence: Fixes crash on Wayland when launching with --quit

fix(dde-lowpower): 修复 Wayland 下 screenAt 返回空指针导致的崩溃

  1. 增加 screenAt 返回空指针的判空保护
  2. 获取不到光标所在屏幕时降级到主屏
  3. 所有屏幕都不可用时提前返回
  4. 避免 QCursor::pos() 返回无效位置时触发 SIGSEGV

Log: 修复 Wayland 下 dde-lowpower 空指针崩溃
PMS: BUG-370187
Influence: 修复 Wayland 下启动崩溃

Summary by Sourcery

Handle missing screen information more safely when sizing the low-power window to prevent crashes on Wayland.

Bug Fixes:

  • Avoid crashes when QCursor::pos() yields a position without an associated screen by falling back to the primary screen and aborting when no screens are available.

Enhancements:

  • Update the SPDX copyright years for the low-power window source file.

…on Wayland

1. Added null check for QScreen pointer returned by screenAt(QCursor::pos())
2. Fallback to primaryScreen() when screenAt fails on Wayland
3. Early return if no screen available at all
4. Prevents SIGSEGV when QCursor::pos() returns invalid position

Log: Fix dde-lowpower crash on Wayland due to null screen pointer
Influence: Fixes crash on Wayland when launching with --quit

fix(dde-lowpower): 修复 Wayland 下 screenAt 返回空指针导致的崩溃

1. 增加 screenAt 返回空指针的判空保护
2. 获取不到光标所在屏幕时降级到主屏
3. 所有屏幕都不可用时提前返回
4. 避免 QCursor::pos() 返回无效位置时触发 SIGSEGV

Log: 修复 Wayland 下 dde-lowpower 空指针崩溃
PMS: BUG-370187
Influence: 修复 Wayland 下启动崩溃
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码修复了空指针解引用问题,增强了程序的健壮性
逻辑正确且无安全漏洞,仅版权年份可能存在笔误

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

Window::setupSize 函数中,新增了对 qApp->screenAt() 返回值的空指针检查,并依次尝试使用 qApp->primaryScreen() 作为后备,若仍为空则提前返回,有效防止了后续 screen->devicePixelRatio()screen->geometry() 的空指针解引用。
潜在问题:无
建议:无

  • 2.代码质量(良好)✓

代码遵循了防御性编程原则,逻辑清晰易读。修改版权年份从2022到2026,可能是一个预期的更新或笔误。
潜在问题:版权年份 2026 可能是笔误,当前年份未到 2026。
建议:确认版权年份是否应为当前年份。

  • 3.代码性能(无性能问题)✓

新增的空指针检查和后备逻辑不会引入明显的性能开销,qApp->primaryScreen() 调用开销极低。
潜在问题:无
建议:无

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次代码修改未引入任何安全漏洞,反而修复了可能导致程序崩溃的空指针解引用问题,提升了系统稳定性。

  • 建议:无需额外安全修复。

■ 【改进建议代码示例】

// SPDX-FileCopyrightText: 2015 - 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
 
// ... 原有代码 ...
 
void Window::setupSize()
{
    setFixedSize(totalWidth, totalHeight);
 
    QScreen *screen = qApp->screenAt(QCursor::pos());
    if (!screen) {
        screen = qApp->primaryScreen();
    }
    if (!screen) {
        return;
    }
 
    const qreal ratio = screen->devicePixelRatio();
    m_image->setFixedSize(m_pix.size() / ratio);
    m_image->move(screen->geometry().center() - m_image->rect().center());
}

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mhduiy, robertkill

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 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In the early-return case when no screen is found, setupSize() exits after setting the window’s fixed size but before sizing/positioning m_image; consider either documenting this behavior or providing a sensible fallback (e.g., centering within a default rect) to avoid partially initialized layout.
  • If the intent is specifically to handle Wayland quirks, it might be helpful to add a short comment above the screenAt/primaryScreen logic explaining why both are tried and why an early return is acceptable when both fail, to aid future maintainers.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the early-return case when no screen is found, `setupSize()` exits after setting the window’s fixed size but before sizing/positioning `m_image`; consider either documenting this behavior or providing a sensible fallback (e.g., centering within a default rect) to avoid partially initialized layout.
- If the intent is specifically to handle Wayland quirks, it might be helpful to add a short comment above the `screenAt`/`primaryScreen` logic explaining why both are tried and why an early return is acceptable when both fail, to aid future maintainers.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@mhduiy
mhduiy merged commit 89484ea into linuxdeepin:master Jul 27, 2026
16 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