Skip to content

fix: prevent QMap operator[] silent insert polluting coreNums - #828

Closed
add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:agent/pms-bug-bot/2252f26938ae
Closed

add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:agent/pms-bug-bot/2252f26938ae

Conversation

@add-uos

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

Copy link
Copy Markdown
Contributor

fix: prevent QMap operator[] silent insert polluting coreNums

  1. PhysicalCpu::logicalCpu fallback path used m_MapCoreCpu[-1] (QMap
    operator[]), which silently inserts a default CoreCpu when key -1
    is absent, polluting m_MapCoreCpu and causing coreNums() to return
    spurious -1 entries
  2. Replace operator[] with find() in both coreCpu(int id) and
    logicalCpu(int id); when key is not found, return a static default
    instance reference instead of inserting into the map
  3. No API signature changes; only internal access pattern changed to
    eliminate implicit insertion side effects

Log: Fix CPU topology data corruption caused by operator[] silent insert

Influence:

  1. Verify CPU topology information displays correctly with no spurious
    entries
  2. Test coreCpu() and logicalCpu() with both existing and non-existing
    IDs to confirm no data pollution
  3. Verify coreNums() returns correct key list without -1 entries

fix: 避免 QMap operator[] 隐式插入污染 coreNums 数据

  1. PhysicalCpu::logicalCpu 的 fallback 路径使用 m_MapCoreCpu[-1](QMap
    operator[]),当 key -1 不存在时隐式插入默认 CoreCpu,污染
    m_MapCoreCpu 数据,导致 coreNums() 返回含虚假 -1 条目
  2. 将 coreCpu(int id) 和 logicalCpu(int id) 中的 operator[] 替换为
    find(),key 不存在时返回静态默认实例引用,不再隐式插入
  3. 不改 API 签名,仅修改内部访问方式,消除隐式插入副作用

Log: 修复 operator[] 隐式插入导致 CPU 拓扑数据错误

Influence:

  1. 验证 CPU 拓扑信息显示正确,无虚假条目
  2. 测试 coreCpu() 和 logicalCpu() 传入存在和不存在的 ID,确认无数据污染
  3. 验证 coreNums() 返回的键列表不含 -1 条目

PMS: BUG-2

Summary by Sourcery

Prevent CPU topology map pollution from missing core and logical CPU lookups.

Bug Fixes:

  • Prevent missing CPU lookups from implicitly inserting entries into the physical CPU map, eliminating spurious -1 entries from coreNums().

Enhancements:

  • Preserve existing lookup APIs while returning default objects for unknown core and logical CPU IDs without mutating topology data.

1. PhysicalCpu::logicalCpu fallback path used m_MapCoreCpu[-1] (QMap
   operator[]), which silently inserts a default CoreCpu when key -1
   is absent, polluting m_MapCoreCpu and causing coreNums() to return
   spurious -1 entries
2. Replace operator[] with find() in both coreCpu(int id) and
   logicalCpu(int id); when key is not found, return a static default
   instance reference instead of inserting into the map
3. No API signature changes; only internal access pattern changed to
   eliminate implicit insertion side effects

Log: Fix CPU topology data corruption caused by operator[] silent insert

Influence:
1. Verify CPU topology information displays correctly with no spurious
   entries
2. Test coreCpu() and logicalCpu() with both existing and non-existing
   IDs to confirm no data pollution
3. Verify coreNums() returns correct key list without -1 entries

fix: 避免 QMap operator[] 隐式插入污染 coreNums 数据

1. PhysicalCpu::logicalCpu 的 fallback 路径使用 m_MapCoreCpu[-1](QMap
   operator[]),当 key -1 不存在时隐式插入默认 CoreCpu,污染
   m_MapCoreCpu 数据,导致 coreNums() 返回含虚假 -1 条目
2. 将 coreCpu(int id) 和 logicalCpu(int id) 中的 operator[] 替换为
   find(),key 不存在时返回静态默认实例引用,不再隐式插入
3. 不改 API 签名,仅修改内部访问方式,消除隐式插入副作用

Log: 修复 operator[] 隐式插入导致 CPU 拓扑数据错误

Influence:
1. 验证 CPU 拓扑信息显示正确,无虚假条目
2. 测试 coreCpu() 和 logicalCpu() 传入存在和不存在的 ID,确认无数据污染
3. 验证 coreNums() 返回的键列表不含 -1 条目

PMS: BUG-2
@sourcery-ai

sourcery-ai Bot commented Oct 10, 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.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos

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 Oct 10, 2026

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

Reviewer's Guide

This PR prevents CPU topology corruption caused by QMap::operator[] inserting missing keys, especially the fallback -1 core. Both lookup methods now use non-mutating find() access and static default references, so querying missing IDs no longer pollutes coreNums() while retaining the existing API.

Sequence diagram for non-mutating CPU lookup

sequenceDiagram
    participant Caller
    participant PhysicalCpu
    participant CoreMap as m_MapCoreCpu
    participant Default as StaticDefault

    Caller->>PhysicalCpu: coreCpu(id)
    PhysicalCpu->>CoreMap: find(id)
    alt key exists
        CoreMap-->>PhysicalCpu: CoreCpu reference
        PhysicalCpu-->>Caller: CoreCpu reference
    else key missing
        PhysicalCpu->>Default: return s_invalidCoreCpu
        Default-->>Caller: CoreCpu reference
    end

    Caller->>PhysicalCpu: logicalCpu(id)
    PhysicalCpu->>CoreMap: find(-1)
    alt fallback key exists
        CoreMap-->>PhysicalCpu: CoreCpu reference
        PhysicalCpu->>CoreMap: logicalCpu(-1)
        CoreMap-->>Caller: LogicalCpu reference
    else fallback key missing
        PhysicalCpu->>Default: return s_invalidLogicalCpu
        Default-->>Caller: LogicalCpu reference
    end
Loading

Flow diagram for preserving coreNums during missing-ID lookup

flowchart LR
    A[Lookup missing CPU ID] --> B[QMap::find]
    B --> C{Key exists?}
    C -->|Yes| D[Return mapped CPU reference]
    C -->|No| E[Return static default reference]
    D --> F[Map remains unchanged]
    E --> F
    F --> G[coreNums returns only real keys]
Loading

File-Level Changes

Change Details Files
Removed implicit QMap insertion from CPU lookup paths by switching to non-mutating searches with static fallback objects.
  • Use QMap::find() in coreCpu(int) and return an existing value when found.
  • Return a static default CoreCpu when the requested core ID is absent.
  • Use QMap::find(-1) in logicalCpu(int) fallback and return a static default LogicalCpu when absent.
  • Preserve existing method signatures and lookup behavior without modifying the topology map.
deepin-devicemanager-server/deepin-deviceinfo/src/loadinfo/cpu/physicalcpu.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

@add-uos add-uos closed this Oct 10, 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.

3 participants