Fix crash while sorting lines with numbers longer than 20 digits
Fix #5261, close #5555pull/5718/head
parent
3e993ff4c7
commit
ff20c264df
|
@ -156,7 +156,21 @@ public:
|
|||
else if (aChunkIsNum)
|
||||
{
|
||||
size_t delta = 0;
|
||||
compareResult = std::stoll(a.substr(i)) - std::stoll(b.substr(i), &delta);
|
||||
|
||||
// stoll crashes if number exceeds the limit for unsigned long long
|
||||
// Maximum value for a variable of type unsigned long long | 18446744073709551615
|
||||
// So take the max length 18 to convert the number
|
||||
const size_t maxLen = 18;
|
||||
size_t aLen = a.length() - i, bLen = b.length() - i;
|
||||
if (aLen > maxLen || bLen > maxLen)
|
||||
{
|
||||
delta = min(min(aLen, bLen), maxLen);
|
||||
compareResult = std::stoll(a.substr(i, delta)) - std::stoll(b.substr(i, delta));
|
||||
}
|
||||
else
|
||||
{
|
||||
compareResult = std::stoll(a.substr(i)) - std::stoll(b.substr(i), &delta);
|
||||
}
|
||||
i += delta;
|
||||
}
|
||||
// Both are strings
|
||||
|
@ -206,7 +220,21 @@ public:
|
|||
else if (aChunkIsNum)
|
||||
{
|
||||
size_t delta = 0;
|
||||
compareResult = std::stoll(a.substr(i)) - std::stoll(b.substr(i), &delta);
|
||||
|
||||
// stoll crashes if number exceeds the limit for unsigned long long
|
||||
// Maximum value for a variable of type unsigned long long | 18446744073709551615
|
||||
// So take the max length 18 to convert the number
|
||||
const size_t maxLen = 18;
|
||||
size_t aLen = a.length() - i, bLen = b.length() - i;
|
||||
if (aLen > maxLen || bLen > maxLen)
|
||||
{
|
||||
delta = min(min(aLen, bLen), maxLen);
|
||||
compareResult = std::stoll(a.substr(i, delta)) - std::stoll(b.substr(i, delta));
|
||||
}
|
||||
else
|
||||
{
|
||||
compareResult = std::stoll(a.substr(i)) - std::stoll(b.substr(i), &delta);
|
||||
}
|
||||
i += delta;
|
||||
}
|
||||
// Both are strings
|
||||
|
|
Loading…
Reference in New Issue