Skip to content

fix: guard cpuinfo flags key before setting - #922

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:agent/bug/4cf4f92fa896
Oct 30, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:agent/bug/4cf4f92fa896

Conversation

@add-uos

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

Copy link
Copy Markdown
Contributor

fix: guard cpuinfo flags key before setting

  1. Root cause: setProcCpuinfo called setFlags(mapInfo["flags"])
    unconditionally; on loongarch64/mips64 where /proc/cpuinfo has no
    flags field, QMap::operator[] returns an empty string and overwrites
    any existing flags value, defeating the isEmpty fallback logic
  2. Fix: add contains("flags") && !isEmpty guard before setFlags so the
    flags value is only set when the key exists and is non-empty
  3. Impact: also fix m_Arch init typo "unknow" to "unknown" in CpuInfo
    constructor; no behavior change on x86, loongarch64/mips64 flags now
    correctly fall back to features field

Influence:

  1. Test CPU info loading on x86 with flags field present
  2. Test CPU info loading on loongarch64/mips64 without flags field
  3. Verify flags fallback to features field works correctly
  4. Verify m_Arch default value spelling is correct

fix: 修复cpuinfo中flags键无条件覆盖问题

  1. 根因:setProcCpuinfo 无条件调用 setFlags(mapInfo["flags"]),
    在 loongarch64/mips64 架构下 /proc/cpuinfo 无 flags 字段时,
    QMap::operator[] 返回空串并覆盖已有 flags 值,导致 isEmpty
    兜底逻辑失效
  2. 方案:在 setFlags 前增加 contains("flags") && !isEmpty 守卫,
    仅当 flags 键存在且非空时才设置,避免无条件覆盖
  3. 影响:同时修复 CpuInfo 构造函数 m_Arch 初始值拼写 "unknow"
    为 "unknown";x86 架构行为不变,loongarch64/mips64 架构下
    flags 正确回退至 features 字段

Influence:

  1. 测试 x86 架构下含 flags 字段的 CPU 信息加载
  2. 测试 loongarch64/mips64 架构下无 flags 字段的 CPU 信息加载
  3. 验证 flags 回退至 features 字段的逻辑正确性
  4. 验证 m_Arch 默认值拼写正确

Summary by Sourcery

Prevent missing CPU flags data from overwriting fallback values and correct the default architecture spelling.

Bug Fixes:

  • Preserve CPU flags fallback behavior when the /proc/cpuinfo flags field is missing or empty.
  • Correct the default CPU architecture value from "unknow" to "unknown".

@sourcery-ai

sourcery-ai Bot commented Oct 26, 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 1 day and 17 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 26, 2026

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

Reviewer's Guide

Guards CPU flags assignment so absent or empty /proc/cpuinfo flags do not erase the features-based fallback, while correcting the CpuInfo default architecture spelling.

Sequence diagram for CPU flags loading and fallback

sequenceDiagram
    participant CpuInfo
    participant LogicalCpu
    participant ProcCpuinfo

    CpuInfo->>ProcCpuinfo: setProcCpuinfo(logical, mapInfo)
    alt flags key exists and is non-empty
        CpuInfo->>LogicalCpu: setFlags(mapInfo[flags])
    else flags key absent or empty
        Note over LogicalCpu: Preserve existing features-based flags fallback
    end
Loading

File-Level Changes

Change Details Files
Prevent missing or empty CPU info flags from overwriting the existing fallback value.
  • Check that the flags key exists and is non-empty before assigning it.
  • Preserve the existing features-based fallback for architectures without a flags field.
deepin-devicemanager-server/deepin-deviceinfo/src/loadinfo/cpu/cpuinfo.cpp
Correct the default architecture value spelling.
  • Initialize the architecture field to "unknown" instead of "unknow".
deepin-devicemanager-server/deepin-deviceinfo/src/loadinfo/cpu/cpuinfo.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


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为 bug 修复,修正了 CpuInfo 构造函数中架构默认值的拼写错误("unknow" → "unknown"),并在 setProcCpuinfo 中对 cpuinfo 的 flags 字段增加存在性与非空校验后再设置,避免在 flags 键缺失时传入空字符串。改动范围小、目的明确、逻辑正确,四维度均无问题,无安全漏洞,OCR 与启发式扫描均未发现问题。

🔍 详细分析

1. 语法逻辑 ✅

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

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

建议: 无


2. 代码质量 ✅

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

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

建议: 可选优化:当前条件判断中两次访问 mapInfo["flags"](contains 一次、取值一次),可考虑使用 QMap::value 或局部变量减少重复查找,但影响极小,非必须。


3. 代码性能 ✅

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

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

建议: 无


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: 无


💡 改进建议代码示例

// 可选:使用局部变量减少重复键查找
void CpuInfo::setProcCpuinfo(LogicalCpu &logical, const QMap<QString, QString> &mapInfo)
{
    const QString flags = mapInfo.value("flags");
    if (!flags.isEmpty())
        logical.setFlags(flags);
    logical.setModel(mapInfo["model"]);
    logical.setModelName(mapInfo["model name"]);
    logical.setVendor(mapInfo["vendor_id"]);
}

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

1. Root cause: setProcCpuinfo called setFlags(mapInfo["flags"])
   unconditionally; on loongarch64/mips64 where /proc/cpuinfo has no
   flags field, QMap::operator[] returns an empty string and overwrites
   any existing flags value, defeating the isEmpty fallback logic
2. Fix: add contains("flags") && !isEmpty guard before setFlags so the
   flags value is only set when the key exists and is non-empty
3. Impact: also fix m_Arch init typo "unknow" to "unknown" in CpuInfo
   constructor; no behavior change on x86, loongarch64/mips64 flags now
   correctly fall back to features field

Influence:
1. Test CPU info loading on x86 with flags field present
2. Test CPU info loading on loongarch64/mips64 without flags field
3. Verify flags fallback to features field works correctly
4. Verify m_Arch default value spelling is correct

fix: 修复cpuinfo中flags键无条件覆盖问题

1. 根因:setProcCpuinfo 无条件调用 setFlags(mapInfo["flags"]),
   在 loongarch64/mips64 架构下 /proc/cpuinfo 无 flags 字段时,
   QMap::operator[] 返回空串并覆盖已有 flags 值,导致 isEmpty
   兜底逻辑失效
2. 方案:在 setFlags 前增加 contains("flags") && !isEmpty 守卫,
   仅当 flags 键存在且非空时才设置,避免无条件覆盖
3. 影响:同时修复 CpuInfo 构造函数 m_Arch 初始值拼写 "unknow"
   为 "unknown";x86 架构行为不变,loongarch64/mips64 架构下
   flags 正确回退至 features 字段

Influence:
1. 测试 x86 架构下含 flags 字段的 CPU 信息加载
2. 测试 loongarch64/mips64 架构下无 flags 字段的 CPU 信息加载
3. 验证 flags 回退至 features 字段的逻辑正确性
4. 验证 m_Arch 默认值拼写正确
@add-uos
add-uos force-pushed the agent/bug/4cf4f92fa896 branch from 216012b to a2a07f2 Compare October 27, 2026 03:43
@deepin-bot

deepin-bot Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.0.75
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #956

@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 30, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot
deepin-bot Bot merged commit d614f75 into linuxdeepin:master Oct 30, 2026
14 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