[plasma/plasma-desktop] kcms/gamecontroller: kcms/gamecontroller: Fix std::out_of_range exception
Sebastian Sauer <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 932f29636ccd264005cb1af579c0c1a11976cbf7 by Sebastian Sauer.
Committed on 20/07/2026 at 04:29.
Pushed by meven into branch 'master'.
kcms/gamecontroller: Fix std::out_of_range exception
If either slash==std::string::npos or devicePath.empty() then
the code can throw a std::out_of_range exception. Fix that
and make sure the code not throws a std::out_of_range exception.
Based on a patch done by Adam Doda.
BUG: 522886
M +1 -1 kcms/gamecontroller/udevmatcher.cpp
https://invent.kde.org/plasma/plasma-desktop/-/commit/932f29636ccd264005cb1af579c0c1a11976cbf7
diff --git a/kcms/gamecontroller/udevmatcher.cpp b/kcms/gamecontroller/udevmatcher.cpp
index 08d4606db3..45ed73e541 100644
--- a/kcms/gamecontroller/udevmatcher.cpp
+++ b/kcms/gamecontroller/udevmatcher.cpp
@@ -55,7 +55,7 @@ std::string UDevMatcher::deviceToUdevId(const std::string &device_path)
qCDebug(KCM_GAMECONTROLLER) << "Looking for ID of " << devicePath;
// If the bit after the last / is a digit, stop, we found it
- while (!std::isdigit(devicePath.at(slash + 1))) {
+ while (slash != std::string::npos && (slash + 1) < devicePath.length() && !std::isdigit(devicePath.at(slash + 1))) {
// Remove the last bit
devicePath = devicePath.substr(0, slash);