[GUI] Avoid overflow in alphanum sorting

This commit is contained in:
VaDiM 2023-03-07 06:55:45 +03:00
parent c52940abc4
commit fb574064c9
2 changed files with 18 additions and 6 deletions

View File

@ -67,11 +67,17 @@ namespace AssetStudioGUI
if (char.IsDigit(space1[0]) && char.IsDigit(space2[0])) if (char.IsDigit(space1[0]) && char.IsDigit(space2[0]))
{ {
int thisNumericChunk = int.Parse(new string(space1)); if (long.TryParse(new string(space1), out long thisNumericChunk) &&
int thatNumericChunk = int.Parse(new string(space2)); long.TryParse(new string(space2), out long thatNumericChunk))
{
result = thisNumericChunk.CompareTo(thatNumericChunk); result = thisNumericChunk.CompareTo(thatNumericChunk);
} }
else else
{
result = MemoryExtensions.CompareTo(space1, space2, StringComparison.Ordinal);
}
}
else
{ {
result = MemoryExtensions.CompareTo(space1, space2, StringComparison.InvariantCultureIgnoreCase); result = MemoryExtensions.CompareTo(space1, space2, StringComparison.InvariantCultureIgnoreCase);
} }

View File

@ -72,11 +72,17 @@ namespace AssetStudioGUI
if (char.IsDigit(space1[0]) && char.IsDigit(space2[0])) if (char.IsDigit(space1[0]) && char.IsDigit(space2[0]))
{ {
int thisNumericChunk = int.Parse(space1); if (long.TryParse(space1, out long thisNumericChunk) &&
int thatNumericChunk = int.Parse(space2); long.TryParse(space2, out long thatNumericChunk))
{
result = thisNumericChunk.CompareTo(thatNumericChunk); result = thisNumericChunk.CompareTo(thatNumericChunk);
} }
else else
{
result = MemoryExtensions.CompareTo(space1, space2, StringComparison.Ordinal);
}
}
else
{ {
result = MemoryExtensions.CompareTo(space1, space2, StringComparison.InvariantCultureIgnoreCase); result = MemoryExtensions.CompareTo(space1, space2, StringComparison.InvariantCultureIgnoreCase);
} }