Version comparison limited by size of "unsigned long" type
Recently I discovered, more-or-less by accident, that version components that have a very large number of digits compare as equal. The cmake documentation does not mention this limitation.
Here is the current code for cmake's component comparison in VersionCompare:
// 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) != 0;
}
if (lhs > rhs) {
// lhs > rhs, so true if operation is GREATER
return (op & cmSystemTools::OP_GREATER) != 0;
}
The use of strtoul()
is the source of the problem. A lexical comparison of the digits would allow effectively unlimited precision.