Skip to content

fix: add null check for QNetworkInformation instance#504

Merged
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:master
Jul 31, 2025
Merged

fix: add null check for QNetworkInformation instance#504
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:master

Conversation

@wyu71
Copy link
Copy Markdown
Contributor

@wyu71 wyu71 commented Jul 30, 2025

  • Added null pointer validation before accessing QNetworkInformation::instance() in networkIsOnline()
  • Prevents potential crash when network information service is unavailable
  • Updated return logic to handle disconnected state properly

Log: add null check for QNetworkInformation instance
pms: BUG-325409

Summary by Sourcery

Add null check around QNetworkInformation::instance() in networkIsOnline and update return logic to handle disconnected state properly

Bug Fixes:

  • Add null pointer validation for QNetworkInformation::instance() to avoid crashes when the network service is unavailable
  • Adjust networkIsOnline return logic to correctly indicate a disconnected state when no network information is available

- Added null pointer validation before accessing QNetworkInformation::instance() in networkIsOnline()
- Prevents potential crash when network information service is unavailable
- Updated return logic to handle disconnected state properly

Log: add null check for QNetworkInformation instance
pms: BUG-325409
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Jul 30, 2025

Reviewer's Guide

Introduce a null pointer check for QNetworkInformation::instance() in networkIsOnline and adjust return logic to avoid crashes and correctly handle disconnected states.

File-Level Changes

Change Details Files
Add null check for QNetworkInformation::instance() and refine networkIsOnline return logic
  • Declare a networkFlag boolean initialized to false
  • Guard QNetworkInformation::instance() calls with an if-statement
  • Retrieve reachability inside the null-check block
  • Set networkFlag based on Disconnected state
  • Return networkFlag instead of direct reachability comparison
deepin-devicemanager/src/Page/PageDriverManager.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

关键摘要:

  • networkIsOnline函数中,增加了对QNetworkInformation::instance()的空指针检查,这是一个好的做法,可以避免潜在的空指针异常。
  • 新增的networkFlag变量用于存储网络状态,但这个变量名不够直观,建议使用更具描述性的名称,如isNetworkDisconnected

是否建议立即修改:

  • 是,建议立即修改networkFlag变量的名称,以提高代码的可读性和可维护性。

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey @wyu71 - I've reviewed your changes - here's some feedback:

  • Consider caching the result of QNetworkInformation::instance() into a local pointer to avoid calling the singleton twice and improve readability.
  • The return condition appears inverted for a method named networkIsOnline(); you likely want to return interfaces != Disconnected instead of interfaces == Disconnected to correctly reflect the online state.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider caching the result of QNetworkInformation::instance() into a local pointer to avoid calling the singleton twice and improve readability.
- The return condition appears inverted for a method named networkIsOnline(); you likely want to return interfaces != Disconnected instead of interfaces == Disconnected to correctly reflect the online state.

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.

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, wyu71

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

@wyu71 wyu71 merged commit bd0c63e into linuxdeepin:master Jul 31, 2025
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