Fixed an issue where a leading Unicode character in the game name could crash the application.

This commit is contained in:
Leon Styhre 2021-01-16 17:22:12 +01:00
parent 8dc23e2114
commit 43da188b3b
2 changed files with 22 additions and 4 deletions

View file

@ -92,10 +92,20 @@ GuiGamelistOptions::GuiGamelistOptions(
ViewController::FAVORITE_CHAR))
isFavorite = true;
if (mFavoritesSorting && file->getFavorite() && isFavorite)
if (mFavoritesSorting && file->getFavorite() && isFavorite) {
mCurrentFirstCharacter = ViewController::FAVORITE_CHAR;
else
mCurrentFirstCharacter = toupper(file->getSortName().front());
}
else {
unsigned char checkCharType = file->getSortName().front();
if (checkCharType <= 0x7F) // Normal ASCII character.
mCurrentFirstCharacter = toupper(file->getSortName().front());
else if (checkCharType >= 0xF0) // Four-byte Unicode character.
mCurrentFirstCharacter = file->getSortName().substr(0, 4);
else if (checkCharType >= 0xE0) // Three-byte Unicode character.
mCurrentFirstCharacter = file->getSortName().substr(0, 3);
else if (checkCharType >= 0xC0) // Two-byte Unicode character.
mCurrentFirstCharacter = file->getSortName().substr(0, 2);
}
}
mJumpToLetterList = std::make_shared<LetterList>(mWindow, getHelpStyle(),

View file

@ -489,7 +489,15 @@ void ISimpleGameListView::generateFirstLetterIndex(const std::vector<FileData*>&
hasFavorites = true;
}
else {
firstChar = toupper((*it)->getSortName().front());
unsigned char checkCharType = (*it)->getSortName().front();
if (checkCharType <= 0x7F) // Normal ASCII character.
firstChar = toupper((*it)->getSortName().front());
else if (checkCharType >= 0xF0) // Four-byte Unicode character.
firstChar = (*it)->getSortName().substr(0, 4);
else if (checkCharType >= 0xE0) // Three-byte Unicode character.
firstChar = (*it)->getSortName().substr(0, 3);
else if (checkCharType >= 0xC0) // Two-byte Unicode character.
firstChar = (*it)->getSortName().substr(0, 2);
mFirstLetterIndex.push_back(firstChar);
}
}