From 7b286352da4f7177e8fd16a1b4162d41239a9816 Mon Sep 17 00:00:00 2001 From: Geoffrey Mon Date: Tue, 30 May 2023 21:52:35 -0500 Subject: [PATCH] Read I2C bus location more reliably --- ProfileManager.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ProfileManager.cpp b/ProfileManager.cpp index 55a74654b..f866373cb 100644 --- a/ProfileManager.cpp +++ b/ProfileManager.cpp @@ -228,11 +228,19 @@ bool ProfileManager::LoadDeviceFromListWithOptions if(load_controller->location.find("HID: ") == 0) { location_check = true; - } + } else if(load_controller->location.find("I2C: ") == 0) { - std::string i2c_address = load_controller->location.substr(load_controller->location.find_last_of(", ") + 2); - location_check = temp_controller->location.find(i2c_address) != std::string::npos; + std::size_t loc = load_controller->location.rfind(", "); + if(loc == std::string::npos) + { + location_check = false; + } + else + { + std::string i2c_address = load_controller->location.substr(loc + 2); + location_check = temp_controller->location.find(i2c_address) != std::string::npos; + } } else {