From 5862ba2d97dfc4f890d19a0e87c15bbf42d21785 Mon Sep 17 00:00:00 2001 From: Dmitry Mikushin Date: Tue, 7 Feb 2023 23:56:04 +0100 Subject: [PATCH] Binary paths array was wrongly iterated up to binaryPaths->length(), which is actually a length of the first string in array, not the array length itself. Rewriting array into a list, so that it could be iterated automatically, without explicitly providing an index range --- GPService/gpservice.cpp | 6 +++--- GPService/gpservice.h | 15 +++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/GPService/gpservice.cpp b/GPService/gpservice.cpp index 40d06b8..fea98b1 100644 --- a/GPService/gpservice.cpp +++ b/GPService/gpservice.cpp @@ -34,9 +34,9 @@ GPService::~GPService() QString GPService::findBinary() { - for (int i = 0; i < binaryPaths->length(); i++) { - if (QFileInfo::exists(binaryPaths[i])) { - return binaryPaths[i]; + for (auto& binaryPath : binaryPaths) { + if (QFileInfo::exists(binaryPath)) { + return binaryPath; } } return nullptr; diff --git a/GPService/gpservice.h b/GPService/gpservice.h index b36ae07..22e9fd4 100644 --- a/GPService/gpservice.h +++ b/GPService/gpservice.h @@ -4,14 +4,13 @@ #include #include -static const QString binaryPaths[] { - "/usr/local/bin/openconnect", - "/usr/local/sbin/openconnect", - "/usr/bin/openconnect", - "/usr/sbin/openconnect", - "/opt/bin/openconnect", - "/opt/sbin/openconnect" -}; +static QList binaryPaths = QList() << + "/usr/local/bin/openconnect" << + "/usr/local/sbin/openconnect" << + "/usr/bin/openconnect" << + "/usr/sbin/openconnect" << + "/opt/bin/openconnect" << + "/opt/sbin/openconnect"; class GPService : public QObject {