From 3d8b834e3c87a40adfe526df1c0089b713fd2f90 Mon Sep 17 00:00:00 2001 From: ComixHe Date: Wed, 15 Nov 2023 10:29:13 +0800 Subject: [PATCH] refact: add some checks Signed-off-by: ComixHe --- src/cgroupsidentifier.cpp | 12 +++++++++++- src/dbus/applicationservice.cpp | 2 +- src/global.h | 4 ++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/cgroupsidentifier.cpp b/src/cgroupsidentifier.cpp index 557348e..0d62ed2 100644 --- a/src/cgroupsidentifier.cpp +++ b/src/cgroupsidentifier.cpp @@ -60,12 +60,22 @@ QString CGroupsIdentifier::parseCGroupsPath(QFile &cgroupFile) noexcept } auto CGPSlices = CGP.split('/', Qt::SkipEmptyParts); + if (CGPSlices.isEmpty()) { + qCritical() << "invalid cgroups path,abort."; + return {}; + } if (CGPSlices.first() != "user.slice") { qWarning() << "unrecognized process."; return {}; } - auto processUIDStr = CGPSlices[1].split('.').first().split('-').last(); + + auto userSlice = CGPSlices.at(1); + if (userSlice.isEmpty()) { + qWarning() << "couldn't detect uid."; + return {}; + } + auto processUIDStr = userSlice.split('.').first().split('-').last(); if (processUIDStr.isEmpty()) { qWarning() << "no uid found."; diff --git a/src/dbus/applicationservice.cpp b/src/dbus/applicationservice.cpp index ee60a6c..b3e027d 100644 --- a/src/dbus/applicationservice.cpp +++ b/src/dbus/applicationservice.cpp @@ -863,7 +863,7 @@ LaunchTask ApplicationService::unescapeExec(const QString &str, const QStringLis } auto list = matcher.capturedTexts(); - if (list.count() > 1) { + if (list.count() != 1) { qWarning() << "invalid exec format, all filed code will be ignored."; for (const auto &code : list) { execList.removeOne(code); diff --git a/src/global.h b/src/global.h index 18d9285..ba68baf 100644 --- a/src/global.h +++ b/src/global.h @@ -473,6 +473,10 @@ inline QString getCurrentDesktop() qWarning() << "multi-DE is detected, use first value."; } + if (desktops.isEmpty()) { + return "DDE"; + } + return desktops.first(); }