summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-10-31 15:35:06 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2014-10-31 15:35:06 (GMT)
commitf2805bd01b011604f95f384ce1759c15503d32cc (patch)
tree01971a7fb6fae972861e9eaf81f7d8a14fa40bcf /Source
parent14a983cce69610a1ed1b57e666d29fdbef4f7cd4 (diff)
parentef09df646a480f4f879f19222a1dfb24316c1d6d (diff)
downloadCMake-f2805bd01b011604f95f384ce1759c15503d32cc.zip
CMake-f2805bd01b011604f95f384ce1759c15503d32cc.tar.gz
CMake-f2805bd01b011604f95f384ce1759c15503d32cc.tar.bz2
Merge topic 'VERSION_no_sscanf'
ef09df64 cmSystemTools: reimplement verson comparison without sscanf() 667560c8 extend the testing for version comparison
Diffstat (limited to 'Source')
-rw-r--r--Source/cmSystemTools.cxx34
1 files changed, 21 insertions, 13 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 6b7009a..3247f7f 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -2634,29 +2634,37 @@ bool cmSystemTools::ChangeRPath(std::string const& file,
bool cmSystemTools::VersionCompare(cmSystemTools::CompareOp op,
const char* lhss, const char* rhss)
{
- // Parse out up to 8 components.
- unsigned int lhs[8] = {0,0,0,0,0,0,0,0};
- unsigned int rhs[8] = {0,0,0,0,0,0,0,0};
- sscanf(lhss, "%u.%u.%u.%u.%u.%u.%u.%u",
- &lhs[0], &lhs[1], &lhs[2], &lhs[3],
- &lhs[4], &lhs[5], &lhs[6], &lhs[7]);
- sscanf(rhss, "%u.%u.%u.%u.%u.%u.%u.%u",
- &rhs[0], &rhs[1], &rhs[2], &rhs[3],
- &rhs[4], &rhs[5], &rhs[6], &rhs[7]);
+ const char *endl = lhss;
+ const char *endr = rhss;
+ unsigned long lhs, rhs;
- // Do component-wise comparison.
- for(unsigned int i=0; i < 8; ++i)
+ while (((*endl >= '0') && (*endl <= '9')) ||
+ ((*endr >= '0') && (*endr <= '9')))
{
- if(lhs[i] < rhs[i])
+ // Do component-wise comparison.
+ lhs = strtoul(endl, const_cast<char**>(&endl), 10);
+ rhs = strtoul(endr, const_cast<char**>(&endr), 10);
+
+ if(lhs < rhs)
{
// lhs < rhs, so true if operation is LESS
return op == cmSystemTools::OP_LESS;
}
- else if(lhs[i] > rhs[i])
+ else if(lhs > rhs)
{
// lhs > rhs, so true if operation is GREATER
return op == cmSystemTools::OP_GREATER;
}
+
+ if (*endr == '.')
+ {
+ endr++;
+ }
+
+ if (*endl == '.')
+ {
+ endl++;
+ }
}
// lhs == rhs, so true if operation is EQUAL
return op == cmSystemTools::OP_EQUAL;