Skip to content

fix: add null check for event pointer in gesture handling - #397

Closed
pengfeixx wants to merge 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/pms-bug-bot/3c38429b9a9f
Closed

pengfeixx wants to merge 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/pms-bug-bot/3c38429b9a9f

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

fix: add null check for event pointer in gesture handling

  1. Root cause: SheetBrowser::event() dereferences event pointer at
    gesture check without null guard, while KeyPress branch already
    guards with "event &&", causing crash when event is null
  2. Fix: add "event &&" null check before event->type() call in the
    Gesture branch, consistent with existing KeyPress branch pattern
  3. Impact: prevents null pointer dereference crash, no behavior change
    for valid event pointers

Log: fix crash caused by null event pointer in gesture event handling

Influence:

  1. Test gesture events with valid event pointer
  2. Test event handling when event pointer is null
  3. Verify no regression on existing keyboard and gesture handling

fix: 修复手势事件处理中的空指针解引用问题

  1. 根因:SheetBrowser::event() 在手势事件检查处直接解引用 event
    指针而未做空检查,而 KeyPress 分支已有 "event &&" 防护,当
    event 为空时导致崩溃
  2. 方案:在 Gesture 分支的 event->type() 调用前添加 "event &&"
    空指针检查,与既有 KeyPress 分支防护模式一致
  3. 影响:防止空指针解引用崩溃,对有效事件指针无行为变化

Log: 修复手势事件处理中空指针导致的崩溃问题

Influence:

  1. 测试有效事件指针的手势事件处理
  2. 测试事件指针为空时的事件处理
  3. 验证现有键盘和手势处理无回归

Summary by Sourcery

Bug Fixes:

  • Prevent null pointer dereferences when handling gesture events without changing behavior for valid events.

1. Root cause: SheetBrowser::event() dereferences event pointer at
   gesture check without null guard, while KeyPress branch already
   guards with "event &&", causing crash when event is null
2. Fix: add "event &&" null check before event->type() call in the
   Gesture branch, consistent with existing KeyPress branch pattern
3. Impact: prevents null pointer dereference crash, no behavior change
   for valid event pointers

Log: fix crash caused by null event pointer in gesture event handling

Influence:
1. Test gesture events with valid event pointer
2. Test event handling when event pointer is null
3. Verify no regression on existing keyboard and gesture handling

fix: 修复手势事件处理中的空指针解引用问题

1. 根因:SheetBrowser::event() 在手势事件检查处直接解引用 event
   指针而未做空检查,而 KeyPress 分支已有 "event &&" 防护,当
   event 为空时导致崩溃
2. 方案:在 Gesture 分支的 event->type() 调用前添加 "event &&"
   空指针检查,与既有 KeyPress 分支防护模式一致
3. 影响:防止空指针解引用崩溃,对有效事件指针无行为变化

Log: 修复手势事件处理中空指针导致的崩溃问题

Influence:
1. 测试有效事件指针的手势事件处理
2. 测试事件指针为空时的事件处理
3. 验证现有键盘和手势处理无回归

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

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

You can request another review in 3 days and 16 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: pengfeixx

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 Sep 18, 2026

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

Reviewer's Guide

Updates SheetBrowser::event() to null-check the event pointer before gesture detection, eliminating the crash path for null events without changing valid keyboard or gesture event handling.

Flow diagram for null-safe gesture event handling

flowchart TD
    A["SheetBrowser::event(QEvent *event)"] --> B{"event is non-null?"}
    B -->|No| C["Continue without gesture dereference"]
    B -->|Yes| D{"event->type() == QEvent::Gesture?"}
    D -->|Yes| E["gestureEvent(reinterpret_cast<QGestureEvent *>(event))"]
    D -->|No| C
Loading

File-Level Changes

Change Details Files
Guard gesture event type inspection against a null event pointer before dispatching to gesture handling.
  • Add an event && check before calling event->type() in SheetBrowser::event().
  • Preserve existing behavior for valid gesture events while preventing null-pointer dereference crashes.
reader/browser/SheetBrowser.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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 100 分,大于 70 分通过阈值,代码质量符合要求。本次变更为空指针解引用修复,代码正确且符合既有模式。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

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

建议: 语法正确,逻辑清晰,无需额外修改


2. 代码质量 ✅

评价: 优秀 ✅ 通过

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

建议: 代码结构清晰,修复方式与既有 KeyPress 分支一致,保持良好的一致性


3. 代码性能 ✅

评价: 优秀 ✅ 通过

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

建议: 性能良好,空指针检查的开销可忽略不计,短路求值保证了效率


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: 本次修复增强了空指针防御性编程,无新增安全漏洞


💡 改进建议代码示例

// 修复后的代码(reader/browser/SheetBrowser.cpp:925)
// 在 Gesture 分支添加 event 空指针检查,与 KeyPress 分支保持一致

bool SheetBrowser::event(QEvent *event)
{
    // KeyPress 分支已有空指针检查
    if (event && event->type() == QEvent::KeyPress) {
        // ...
    }

    // 修复:添加 event && 空指针检查
    if (event && event->type() == QEvent::Gesture) {
        return gestureEvent(reinterpret_cast<QGestureEvent *>(event));
    }

    return QGraphicsView::event(event);
}

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

@pengfeixx

Copy link
Copy Markdown
Contributor Author

Superseded by #400, which combines this fix with #395 into a single commit (same content).

@pengfeixx pengfeixx closed this Sep 20, 2026
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