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

summaryrefslogtreecommitdiffhomepage
path: root/tools/Versions.cpp
diff options
context:
space:
mode:
authorLeitwolf112026-11-14 22:42:54 +0300
committerLeitwolf112026-11-14 22:42:54 +0300
commite2905c736cf2e36965c071c21bc7911eb3c59a7b (patch)
tree537504b761ed21b6fe821aebbbf9eab6b398d054 /tools/Versions.cpp
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/Versions.cpp')
-rw-r--r--tools/Versions.cpp6
1 files changed, 5 insertions, 1 deletions
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;
}