mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-05 00:42:48 +00:00
Fixed integer overflow when refreshing grid list
This commit is contained in:
parent
4040f58af6
commit
bd4cd9632c
@ -38,17 +38,34 @@ GameGridFrame::GameGridFrame(std::shared_ptr<GameInfoClass> game_info_get,
|
|||||||
|
|
||||||
void GameGridFrame::onCurrentCellChanged(int currentRow, int currentColumn, int previousRow,
|
void GameGridFrame::onCurrentCellChanged(int currentRow, int currentColumn, int previousRow,
|
||||||
int previousColumn) {
|
int previousColumn) {
|
||||||
crtRow = currentRow;
|
// Early exit for invalid indices
|
||||||
crtColumn = currentColumn;
|
if (currentRow < 0 || currentColumn < 0) {
|
||||||
columnCnt = this->columnCount();
|
|
||||||
|
|
||||||
auto itemID = (crtRow * columnCnt) + currentColumn;
|
|
||||||
if (itemID > m_game_info->m_games.count() - 1) {
|
|
||||||
cellClicked = false;
|
cellClicked = false;
|
||||||
validCellSelected = false;
|
validCellSelected = false;
|
||||||
BackgroundMusicPlayer::getInstance().stopMusic();
|
BackgroundMusicPlayer::getInstance().stopMusic();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
crtRow = currentRow;
|
||||||
|
crtColumn = currentColumn;
|
||||||
|
columnCnt = this->columnCount();
|
||||||
|
|
||||||
|
// Prevent integer overflow
|
||||||
|
if (columnCnt <= 0 || crtRow > (std::numeric_limits<int>::max() / columnCnt)) {
|
||||||
|
cellClicked = false;
|
||||||
|
validCellSelected = false;
|
||||||
|
BackgroundMusicPlayer::getInstance().stopMusic();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto itemID = (crtRow * columnCnt) + currentColumn;
|
||||||
|
if (itemID < 0 || itemID > m_game_info->m_games.count() - 1) {
|
||||||
|
cellClicked = false;
|
||||||
|
validCellSelected = false;
|
||||||
|
BackgroundMusicPlayer::getInstance().stopMusic();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
cellClicked = true;
|
cellClicked = true;
|
||||||
validCellSelected = true;
|
validCellSelected = true;
|
||||||
SetGridBackgroundImage(crtRow, crtColumn);
|
SetGridBackgroundImage(crtRow, crtColumn);
|
||||||
|
Loading…
Reference in New Issue
Block a user