Skip to content
Snippets Groups Projects
Commit 7eb1fff6 authored by Florian Fischer's avatar Florian Fischer
Browse files

[LinuxVersion] fix version comparison

LinuxVersion used the assumption that both strings have the same
amount of dot-separated components.
But this is obviously not always the case.
If we can't compare the two strings further they must been equal so far.
parent 9d627462
No related branches found
No related tags found
1 merge request!296fix Future::cancel with new Scheduler::scheduleOn(fiber, workerId)
......@@ -2,7 +2,6 @@
// Copyright © 2021 Florian Fischer
#include "lib/LinuxVersion.hpp"
#include <cassert>
#include <cerrno>
#include <cstdlib>
......@@ -47,7 +46,8 @@ auto LinuxVersion::compare(const std::string& s) -> int {
dot_pos2 = s.size();
} else {
dot_pos2 = s.find('.', last_dot_pos2);
assert(dot_pos2 != std::string::npos);
// The string to compare has less dot-separated components
if (dot_pos2 == std::string::npos) return 0;
}
long n1 = checked_strtol(this->version.substr(last_dot_pos, dot_pos - last_dot_pos));
......
......@@ -73,3 +73,9 @@ TEST(LinuxVersion, ge) {
ASSERT_TRUE(TestLinuxVersion::ge("5.14.0", "4.13"));
ASSERT_TRUE(TestLinuxVersion::ge("5.14.0", "5.14.0"));
}
// NOLINTNEXTLINE(modernize-use-trailing-return-type)
TEST(LinuxVersion, real_world) {
ASSERT_TRUE(TestLinuxVersion::le("5.15.0-0.bpo.2-amd64", "5.15.0"));
ASSERT_TRUE(TestLinuxVersion::ge("5.17.0", "5.15.0-0.bpo.2-amd64"));
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment