Repository navigation
fix: add null check before clearWidgets in updateTable - #868
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuidePrevents a first-call null-pointer dereference in updateTable by conditionally clearing widgets, while leaving subsequent update behavior unchanged. Sequence diagram for safe first updateTable invocationsequenceDiagram
participant Caller
participant PageInfoWidget
participant PageInfo
Caller->>PageInfoWidget: updateTable(itemStr, lst)
alt mp_PageInfo exists
PageInfoWidget->>PageInfo: clearWidgets()
else mp_PageInfo is nullptr
PageInfoWidget->>PageInfoWidget: Continue without clearWidgets()
end
PageInfoWidget->>PageInfoWidget: Update device information
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
1. Root cause: mp_PageInfo is initialized to nullptr in constructor and only assigned later in updateTable, but clearWidgets() is called unconditionally at function entry before any assignment 2. Fix: add null pointer check before calling clearWidgets() to prevent segfault on first invocation when mp_PageInfo is still nullptr 3. Update SPDX copyright year from 2022 to 2022-2026 to reflect modification year per CI copyright header requirements 4. Impact: prevents crash on first call to updateTable, no behavior change for subsequent calls where mp_PageInfo is already assigned Influence: 1. Test updateTable first invocation with empty device list 2. Test updateTable with single device and multiple devices 3. Verify no regression on existing device info display scenarios fix: 修复updateTable中clearWidgets空指针解引用崩溃 1. 根因:mp_PageInfo在构造函数中初始化为nullptr,仅在updateTable 内部条件分支中赋值,但clearWidgets()在函数入口无条件调用 先于所有赋值逻辑执行 2. 方案:在调用clearWidgets()前增加空指针检查,首次调用时 mp_PageInfo为nullptr则跳过避免段错误 3. 更新SPDX版权年份从2022改为2022-2026以符合CI版权头规范 4. 影响:防止首次调用updateTable时崩溃,对后续调用无行为变化 Influence: 1. 测试首次调用updateTable传入空设备列表 2. 测试单个设备和多设备场景的updateTable调用 3. 验证现有设备信息显示场景无回归 PMS: BUG-DM-DEF-002
f10a20d to
1fcc282
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: [] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: [] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: ['建议在 PageInfoWidget 类的其他方法中统一排查 mp_PageInfo 指针的使用,确保所有解引用处均有空指针保护,形成一致的防御性编程风格。'] 💡 改进建议代码示例// 当前实现已是正确的修复方式,无需额外修改:
void PageInfoWidget::updateTable(const QString &itemStr, const QList<DeviceBaseInfo *> &lst)
{
qCDebug(appLog) << "Updating table with" << lst.size() << "devices, type:" << itemStr;
if (mp_PageInfo) {
mp_PageInfo->clearWidgets();
}
// 设备个数为0,是概况界面
if (lst.size() == 0) {
// ...
}
}本报告由 AI 代码审查工具自动生成 |
|
[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: add null check before clearWidgets in updateTable
and only assigned later in updateTable, but clearWidgets() is called
unconditionally at function entry before any assignment
segfault on first invocation when mp_PageInfo is still nullptr
change for subsequent calls where mp_PageInfo is already assigned
Influence:
fix: 修复updateTable中clearWidgets空指针解引用崩溃
内部条件分支中赋值,但clearWidgets()在函数入口无条件调用
先于所有赋值逻辑执行
mp_PageInfo为nullptr则跳过避免段错误
Influence:
PMS: BUG-DM-DEF-002
Summary by Sourcery
Bug Fixes:
updateTableinvocation from crashing when page information has not yet been initialized.