summaryrefslogtreecommitdiffstats
path: root/Tests/CMakeLib
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-04-11 16:56:32 (GMT)
committerBrad King <brad.king@kitware.com>2019-04-11 16:56:32 (GMT)
commitf0948499f6b47a7a856aef3334a8d8a38c1265d5 (patch)
tree4f2ac14d379cf7b4f57c92416593f2ef6e2c54cb /Tests/CMakeLib
parenta550e2d6e48798d342a5ba7436013c6aa6ce5151 (diff)
downloadCMake-f0948499f6b47a7a856aef3334a8d8a38c1265d5.zip
CMake-f0948499f6b47a7a856aef3334a8d8a38c1265d5.tar.gz
CMake-f0948499f6b47a7a856aef3334a8d8a38c1265d5.tar.bz2
cmSystemTools: Fix StringToULong to reject negative numbers
Fixes: #19161
Diffstat (limited to 'Tests/CMakeLib')
-rw-r--r--Tests/CMakeLib/testSystemTools.cxx17
1 files changed, 17 insertions, 0 deletions
diff --git a/Tests/CMakeLib/testSystemTools.cxx b/Tests/CMakeLib/testSystemTools.cxx
index 96a4819..121e639 100644
--- a/Tests/CMakeLib/testSystemTools.cxx
+++ b/Tests/CMakeLib/testSystemTools.cxx
@@ -93,5 +93,22 @@ int testSystemTools(int /*unused*/, char* /*unused*/ [])
if (!failed) {
cmPassed("cmSystemTools::strverscmp working");
}
+
+ // ----------------------------------------------------------------------
+ // Test cmSystemTools::StringToULong
+ {
+ unsigned long value;
+ cmAssert(cmSystemTools::StringToULong("1", &value) && value == 1,
+ "StringToULong parses a decimal integer.");
+ cmAssert(cmSystemTools::StringToULong(" 1", &value) && value == 1,
+ "StringToULong parses a decimal integer after whitespace.");
+ cmAssert(!cmSystemTools::StringToULong("-1", &value),
+ "StringToULong rejects a negative number.");
+ cmAssert(!cmSystemTools::StringToULong(" -1", &value),
+ "StringToULong rejects a negative number after whitespace.");
+ cmAssert(!cmSystemTools::StringToULong("1x", &value),
+ "StringToULong rejects trailing content.");
+ }
+
return failed;
}