Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Refuse a next patch past the largest number

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
Commit
e2905c736cf2e36965c071c21bc7911eb3c59a7b
Author
Leitwolf11 ·
Parents
2d21d2e0f9c6

Files · Download .tar.gz

Changes

 tools/Tools.tests.cpp | 4 ++++
 tools/Versions.cpp    | 6 +++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

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;
         }