diff --git a/emper/lib/LinuxVersion.cpp b/emper/lib/LinuxVersion.cpp index 4fb3c582d9e4a5ac97f041c249add63fc82294c6..d17aba6319653cb4b7b1b37acfa85bd0f51df8aa 100644 --- a/emper/lib/LinuxVersion.cpp +++ b/emper/lib/LinuxVersion.cpp @@ -74,8 +74,10 @@ auto LinuxVersion::compare(const std::string& s) -> int { dot_pos2 = s.size(); } else { dot_pos2 = s.find('.', last_dot_pos2); - // The string to compare has less dot-separated components - if (dot_pos2 == std::string::npos) return 0; + if (dot_pos2 == std::string::npos) { + dot_pos2 = s.size(); + was_last = true; + } } long n1 = checked_strtol(this->version.substr(last_dot_pos, dot_pos - last_dot_pos)); diff --git a/emper/lib/LinuxVersion.hpp b/emper/lib/LinuxVersion.hpp index 42eb611ebc0c797c7376f726d59c6cfe439a9bbb..870534e68df096ab1ae2d40a680248624297c893 100644 --- a/emper/lib/LinuxVersion.hpp +++ b/emper/lib/LinuxVersion.hpp @@ -25,9 +25,9 @@ class LinuxVersion { auto operator==(const std::string& s) -> bool { return compare(s) == 0; } - auto operator>=(const std::string& s) -> bool { return *this > s || *this == s; } + auto operator>=(const std::string& s) -> bool { return compare(s) >= 0; } - auto operator<=(const std::string& s) -> bool { return *this < s || *this == s; } + auto operator<=(const std::string& s) -> bool { return compare(s) <= 0; } }; } // namespace emper::lib diff --git a/tests/lib/LinuxVersionTest.cpp b/tests/lib/LinuxVersionTest.cpp index 4f171a74b2a5a98d91dc0725cf90405328b3a12c..82a27da206942418ea07c070ab128e6ca126b324 100644 --- a/tests/lib/LinuxVersionTest.cpp +++ b/tests/lib/LinuxVersionTest.cpp @@ -66,12 +66,14 @@ TEST(LinuxVersion, gt) { ASSERT_TRUE(TestLinuxVersion::gt("5.14.0", "5.13.0")); ASSERT_TRUE(TestLinuxVersion::gt("5.13.2", "5.13-foo.1")); ASSERT_TRUE(TestLinuxVersion::gt("5.13.2", "5.13.1-foo")); + ASSERT_FALSE(TestLinuxVersion::gt("5.16.12-arch1-1", "5.18")); } // NOLINTNEXTLINE(modernize-use-trailing-return-type) TEST(LinuxVersion, ge) { ASSERT_TRUE(TestLinuxVersion::ge("5.14.0", "4.13")); ASSERT_TRUE(TestLinuxVersion::ge("5.14.0", "5.14.0")); + ASSERT_FALSE(TestLinuxVersion::ge("5.16.12-arch1-1", "5.18")); } // NOLINTNEXTLINE(modernize-use-trailing-return-type)