Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorLeitwolf112026-11-14 22:42:54 +0300
committerLeitwolf112026-11-14 22:42:54 +0300
commite2905c736cf2e36965c071c21bc7911eb3c59a7b (patch)
tree537504b761ed21b6fe821aebbbf9eab6b398d054 /tools
parent2d21d2e0f9c6e0789e9c55d6cba611234dc61a60 (diff)
downloadcatch3-fix/version-tool-semver.tar.gz
Refuse a next patch past the largest numberfix/version-tool-semver
NextPatch added one to the patch without a check, so a patch at std::numeric_limits<unsigned>::max() wrapped to 0 and --next would have moved the version back. It returns nothing there now; tests cover a three- and a four-number version at the limit. Claude-Session: https://claude.ai/code/session_01Ji7xZMYjc4zankoc7hGBE1
Diffstat (limited to 'tools')
-rw-r--r--tools/Tools.tests.cpp4
-rw-r--r--tools/Versions.cpp6
2 files changed, 9 insertions, 1 deletions
diff --git a/tools/Tools.tests.cpp b/tools/Tools.tests.cpp
index 980d9e7a..c505b966 100644
--- a/tools/Tools.tests.cpp
+++ b/tools/Tools.tests.cpp
@@ -3,6 +3,7 @@
#include <Progmasoft/Catch3/Matchers/String.hpp>
#include <Progmasoft/Catch3/TestMacros.hpp>
+#include <limits>
#include <string>
#include "tools/Amalgamation.hpp"
@@ -38,6 +39,9 @@ TEST_CASE("The next patch release follows a SemVer or a four-number version",
// After the four-number versions: the fourth number goes.
CHECK(next("0.3.0.2") == "0.3.1");
CHECK(next("0.3") == "none");
+ const auto largest = std::to_string(std::numeric_limits<unsigned>::max());
+ CHECK(next(("0.4." + largest).c_str()) == "none");
+ CHECK(next(("0.3." + largest + ".2").c_str()) == "none");
CHECK(next("0.3.0.2.1") == "none");
}
diff --git a/tools/Versions.cpp b/tools/Versions.cpp
index acc0fb4e..d3ae03cf 100644
--- a/tools/Versions.cpp
+++ b/tools/Versions.cpp
@@ -4,6 +4,7 @@
#include <algorithm>
#include <cctype>
#include <charconv>
+#include <limits>
#include <utility>
#include <vector>
@@ -73,7 +74,10 @@ namespace Progmasoft::Catch3::Tools
NextPatch(std::string_view current)
{
const auto numbers = Numbers(current, 4);
- if (!numbers || numbers->size() < 3)
+ // A patch number at its largest has no next one; adding one would
+ // wrap around to 0 and move the version back.
+ if (!numbers || numbers->size() < 3
+ || (*numbers)[2] == std::numeric_limits<unsigned>::max())
{
return std::nullopt;
}