From f2d376308e1e7840c3d7183796f6a3a24a15d530 Mon Sep 17 00:00:00 2001 From: zhaofangxun Date: Tue, 22 Sep 2026 11:36:18 +0800 Subject: [PATCH] fix(datetime): guard against empty date format string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Add early return when the format string is empty after stripping the year token 2. Prevent out-of-bounds access on format.at(0) with an empty format Log: Avoid potential crash when a short date format becomes empty after year removal Influence: Prevents dock crash on empty short date format fix(datetime): 防止短日期格式字符串为空 1. 在移除年份标记后格式字符串为空时提前返回 2. 避免空格式串上 format.at(0) 的越界访问 Log: 避免短日期格式移除年份后为空导致的潜在崩溃 PMS: TASK-395933 Influence: 修复空短日期格式可能导致的崩溃 --- plugins/dde-dock/datetime/regionFormat.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/dde-dock/datetime/regionFormat.cpp b/plugins/dde-dock/datetime/regionFormat.cpp index 3d5cc3d1b..3cb062e34 100755 --- a/plugins/dde-dock/datetime/regionFormat.cpp +++ b/plugins/dde-dock/datetime/regionFormat.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2011 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2011 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -86,6 +86,9 @@ void RegionFormat::setShortDateFormat(const QString &newShortDateFormat) format.remove('Y'); } + if (format.isEmpty()) + return; + if (!format.at(0).isLetter()) { format.remove(0, 1); }