From 723161e3eae6f5ebb380e0f318783b8ac2c605d4 Mon Sep 17 00:00:00 2001 From: zhanghongyuan Date: Mon, 26 Oct 2026 20:34:22 +0800 Subject: [PATCH 1/2] fix: add null check for DStyle cast in view delegates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. dynamic_cast(DApplication::style()) return value was dereferenced without null check, causing SIGSEGV when the app style is not a DStyle derivative 2. Add null check with fallback default values (margin=10, radius=8) in paint(), drawRow() and sectionSizeHint() to prevent crash 3. Emit qCWarning(appLog) when style is null for diagnostics 4. Consistent with the 11 existing null-check guards in the codebase Log: fix potential crash in non-DStyle style environments Influence: 1. Verify device list view renders correctly under DStyle environment 2. Verify no crash when running under non-DStyle (e.g. QApplication) environment 3. Verify log view header sizing is correct fix: 修复视图委托中 DStyle 转换未判空导致的崩溃 1. dynamic_cast(DApplication::style()) 返回值未判空即解引用, 非派生自 DStyle 的样式环境下导致段错误 2. 在 paint()、drawRow()、sectionSizeHint() 中添加判空并回退默认值 (margin=10, radius=8),防止崩溃 3. style 为空时输出 qCWarning(appLog) 日志便于排查 4. 与代码库中已有 11 处判空保护模式风格统一 Log: 修复非 DStyle 样式环境下的潜在崩溃问题 Influence: 1. 验证 DStyle 环境下设备列表视图渲染正常 2. 验证非 DStyle 环境(如 QApplication)下不崩溃 3. 验证日志视图表头尺寸计算正确 PMS: BUG-DEF-001 --- deepin-devicemanager/src/Widget/DriverListView.cpp | 7 ++++++- deepin-devicemanager/src/Widget/DriverListViewDelegate.cpp | 7 ++++++- deepin-devicemanager/src/Widget/logviewheaderview.cpp | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/deepin-devicemanager/src/Widget/DriverListView.cpp b/deepin-devicemanager/src/Widget/DriverListView.cpp index 6f5f42056..071d1cac3 100644 --- a/deepin-devicemanager/src/Widget/DriverListView.cpp +++ b/deepin-devicemanager/src/Widget/DriverListView.cpp @@ -109,7 +109,12 @@ void DriverListView::drawRow(QPainter *painter, const QStyleOptionViewItem &opti auto *style = dynamic_cast(DApplication::style()); - auto radius = style->pixelMetric(DStyle::PM_FrameRadius, &options); + auto radius = 8; + if (style) { + radius = style->pixelMetric(DStyle::PM_FrameRadius, &options); + } else { + qCWarning(appLog) << "Failed to get DStyle, using default radius"; + } //根据实际情况设置颜色,奇数行为灰色 auto palette = options.palette; QBrush background; diff --git a/deepin-devicemanager/src/Widget/DriverListViewDelegate.cpp b/deepin-devicemanager/src/Widget/DriverListViewDelegate.cpp index d2e5337a4..aef7725d8 100644 --- a/deepin-devicemanager/src/Widget/DriverListViewDelegate.cpp +++ b/deepin-devicemanager/src/Widget/DriverListViewDelegate.cpp @@ -77,7 +77,12 @@ void DriverListViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem } } DStyle *style = dynamic_cast(DApplication::style()); - int margin = style->pixelMetric(DStyle::PM_ContentsMargins, &option); + int margin = 10; + if (style) { + margin = style->pixelMetric(DStyle::PM_ContentsMargins, &option); + } else { + qCWarning(appLog) << "Failed to get DStyle, using default margin"; + } //设置高亮文字色 DGuiApplicationHelper *dAppHelper = DGuiApplicationHelper::instance(); DPalette palette = dAppHelper->applicationPalette(); diff --git a/deepin-devicemanager/src/Widget/logviewheaderview.cpp b/deepin-devicemanager/src/Widget/logviewheaderview.cpp index 2acfd3dee..0194eb03e 100644 --- a/deepin-devicemanager/src/Widget/logviewheaderview.cpp +++ b/deepin-devicemanager/src/Widget/logviewheaderview.cpp @@ -187,7 +187,12 @@ int LogViewHeaderView::sectionSizeHint(int logicalIndex) const QStyleOptionHeader option; initStyleOption(&option); DStyle *style = dynamic_cast(DApplication::style()); - int margin = style->pixelMetric(DStyle::PM_ContentsMargins, &option); + int margin = 10; + if (style) { + margin = style->pixelMetric(DStyle::PM_ContentsMargins, &option); + } else { + qCWarning(appLog) << "Failed to get DStyle, using default margin"; + } QFontMetrics fm(DApplication::font()); QString buf = model()->headerData(logicalIndex, Qt::Horizontal, Qt::DisplayRole).toString(); From f4c82438fd7c864e6333712990ca76aab46db1a0 Mon Sep 17 00:00:00 2001 From: zhanghongyuan Date: Tue, 27 Oct 2026 09:24:16 +0800 Subject: [PATCH 2/2] chore: update SPDX copyright year for CI SPDX check The license-check CI (SPDX Header Validation) rejects headers whose year range does not reach the current year. Extend the legacy copyright headers of DriverListView.cpp and DriverListViewDelegate.cpp (2019 ~ 2020) so 2026 is covered and the SPDX summary reports 0 failures. --- deepin-devicemanager/src/Widget/DriverListView.cpp | 2 +- deepin-devicemanager/src/Widget/DriverListViewDelegate.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deepin-devicemanager/src/Widget/DriverListView.cpp b/deepin-devicemanager/src/Widget/DriverListView.cpp index 071d1cac3..c06ffe4d5 100644 --- a/deepin-devicemanager/src/Widget/DriverListView.cpp +++ b/deepin-devicemanager/src/Widget/DriverListView.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019 ~ 2020 UnionTech Software Technology Co.,Ltd +// Copyright (C) 2019-2026 ~ 2020 UnionTech Software Technology Co.,Ltd // SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later diff --git a/deepin-devicemanager/src/Widget/DriverListViewDelegate.cpp b/deepin-devicemanager/src/Widget/DriverListViewDelegate.cpp index aef7725d8..9b9db6bff 100644 --- a/deepin-devicemanager/src/Widget/DriverListViewDelegate.cpp +++ b/deepin-devicemanager/src/Widget/DriverListViewDelegate.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019 ~ 2020 UnionTech Software Technology Co.,Ltd +// Copyright (C) 2019-2026 ~ 2020 UnionTech Software Technology Co.,Ltd // SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later