fix(touchscreen-dialog): fix crash when monitor list changes#424
Open
electricface wants to merge 1 commit intolinuxdeepin:masterfrom
Open
fix(touchscreen-dialog): fix crash when monitor list changes#424electricface wants to merge 1 commit intolinuxdeepin:masterfrom
electricface wants to merge 1 commit intolinuxdeepin:masterfrom
Conversation
When `m_listCombo->clear()` is called in `onMonitorChanged()`, Qt emits `currentIndexChanged(-1)`, triggering `markDisplay(-1)` and causing an out-of-bounds crash on `m_monitors[-1]`. Add a boundary check in `markDisplay()` to return early on invalid index. Log: fix crash when monitor list changes pms: BUG-315115
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: electricface 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 |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds bounds checking to TouchscreenSetting::markDisplay to prevent out-of-bounds access when the monitor list changes and updates the SPDX copyright year range. Sequence diagram for monitor list change causing markDisplay invocationsequenceDiagram
participant Qt as QtFramework
participant Combo as MonitorListComboBox
participant TS as TouchscreenSetting
Qt->>Combo: monitorsChanged()
Combo->>Combo: clear()
Combo-->>TS: currentIndexChanged(-1)
TS->>TS: markDisplay(-1)
TS->>TS: index < 0 or index >= m_monitors.size()
TS-->>TS: return (no access to m_monitors)
Class diagram for updated TouchscreenSetting bounds checkingclassDiagram
class TouchscreenSetting {
- QList~QRect*~ m_monitors
+ bool monitorsIsIntersect() const
+ void markDisplay(int index)
}
class QRect
TouchscreenSetting --> QRect : uses in m_monitors
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review这段代码的修改主要涉及版权年份更新和边界检查的增加。以下是对这段 diff 的详细审查和改进建议: 1. 语法逻辑审查版权年份更新: // SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
边界检查: void TouchscreenSetting::markDisplay(int index)
{
if (index < 0 || index >= m_monitors.size())
return;
2. 代码质量审查边界检查的改进: void TouchscreenSetting::markDisplay(int index)
{
if (index < 0 || index >= m_monitors.size()) {
qWarning() << "Invalid monitor index:" << index << "Valid range: 0 -" << m_monitors.size() - 1;
return;
}
函数命名和注释:
3. 代码性能审查
4. 代码安全审查
5. 改进后的代码示例// SPDX-FileCopyrightText: 2019 - 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
void TouchscreenSetting::markMonitorDisplay(int index)
{
// 边界检查
if (index < 0 || index >= m_monitors.size()) {
qWarning() << "Invalid monitor index:" << index << "Valid range: 0 -" << m_monitors.size() - 1;
return;
}
// 空指针检查(如果需要)
if (!m_monitors[index]) {
qWarning() << "Monitor at index" << index << "is null";
return;
}
// 考虑设备像素比,确保示意框大小与实际显示器大小一致
const auto ratio = qApp->devicePixelRatio();
QRect displayRect(m_monitors[index]->x(), m_monitors[index]->y(),
m_monitors[index]->width() * ratio,
m_monitors[index]->height() * ratio);
// 其余逻辑...
}6. 总结
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
m_listCombo->clear()is called inonMonitorChanged(), Qtemits
currentIndexChanged(-1), triggeringmarkDisplay(-1)andcausing an out-of-bounds crash on
m_monitors[-1].Add a boundary check in
markDisplay()to return early on invalid index.Log: fix crash when monitor list changes
pms: BUG-315115
Summary by Sourcery
Prevent crashes in the touchscreen settings dialog when the monitor list changes and the selected monitor index becomes invalid.
Bug Fixes:
Enhancements: