Repository navigation
fix: guard cpuinfo flags key before setting - #922
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideGuards 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 fallbacksequenceDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: 无 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: 可选优化:当前条件判断中两次访问 mapInfo["flags"](contains 一次、取值一次),可考虑使用 QMap::value 或局部变量减少重复查找,但影响极小,非必须。 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: 无 4. 代码安全 🔒评价: 存在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 默认值拼写正确
216012b to
a2a07f2
Compare
|
TAG Bot New tag: 6.0.75 |
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
fix: guard cpuinfo flags key before setting
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
flags value is only set when the key exists and is non-empty
constructor; no behavior change on x86, loongarch64/mips64 flags now
correctly fall back to features field
Influence:
fix: 修复cpuinfo中flags键无条件覆盖问题
在 loongarch64/mips64 架构下 /proc/cpuinfo 无 flags 字段时,
QMap::operator[] 返回空串并覆盖已有 flags 值,导致 isEmpty
兜底逻辑失效
仅当 flags 键存在且非空时才设置,避免无条件覆盖
为 "unknown";x86 架构行为不变,loongarch64/mips64 架构下
flags 正确回退至 features 字段
Influence:
Summary by Sourcery
Prevent missing CPU flags data from overwriting fallback values and correct the default architecture spelling.
Bug Fixes: