Update AppModel, ComputerModel, and StreamUtil asserts to cover negative indices

This commit is contained in:
Cameron Gutman committed 2026-11-15 00:33:01 -06:00
1 parent 2d600c4e6b
commit 4e8fc3aead
3 files changed
+13 -13

No files matched your search

+5 -5
View File
@@ -13,7 +13,7 @@ void AppModel::initialize(ComputerManager* computerManager, int computerIndex, b
connect(m_ComputerManager, &ComputerManager::computerStateChanged,
this, &AppModel::handleComputerStateChanged);
Q_ASSERT(computerIndex < m_ComputerManager->getComputers().count());
Q_ASSERT(computerIndex >= 0 && computerIndex < m_ComputerManager->getComputers().count());
m_Computer = m_ComputerManager->getComputers().at(computerIndex);
m_CurrentGameId = m_Computer->currentGameId;
m_ShowHiddenGames = showHiddenGames;
@@ -41,7 +41,7 @@ QString AppModel::getRunningAppName()
Session* AppModel::createSessionForApp(int appIndex)
{
Q_ASSERT(appIndex < m_VisibleApps.count());
Q_ASSERT(appIndex >= 0 && appIndex < m_VisibleApps.count());
NvApp app = m_VisibleApps.at(appIndex);
return new Session(m_Computer, app);
@@ -73,7 +73,7 @@ QVariant AppModel::data(const QModelIndex &index, int role) const
if (!index.isValid())
return QVariant();
Q_ASSERT(index.row() < m_VisibleApps.count());
Q_ASSERT(index.row() >= 0 && index.row() < m_VisibleApps.count());
NvApp app = m_VisibleApps.at(index.row());
switch (role)
@@ -207,7 +207,7 @@ void AppModel::updateAppList(QVector<NvApp> newList)
void AppModel::setAppHidden(int appIndex, bool hidden)
{
Q_ASSERT(appIndex < m_VisibleApps.count());
Q_ASSERT(appIndex >= 0 && appIndex < m_VisibleApps.count());
int appId = m_VisibleApps.at(appIndex).id;
{
@@ -226,7 +226,7 @@ void AppModel::setAppHidden(int appIndex, bool hidden)
void AppModel::setAppDirectLaunch(int appIndex, bool directLaunch)
{
Q_ASSERT(appIndex < m_VisibleApps.count());
Q_ASSERT(appIndex >= 0 && appIndex < m_VisibleApps.count());
int appId = m_VisibleApps.at(appIndex).id;
{
+6 -6
View File
@@ -22,7 +22,7 @@ QVariant ComputerModel::data(const QModelIndex& index, int role) const
return QVariant();
}
Q_ASSERT(index.row() < m_Computers.count());
Q_ASSERT(index.row() >= 0 && index.row() < m_Computers.count());
NvComputer* computer = m_Computers[index.row()];
QReadLocker lock(&computer->lock);
@@ -116,7 +116,7 @@ QHash<int, QByteArray> ComputerModel::roleNames() const
Session* ComputerModel::createSessionForCurrentGame(int computerIndex)
{
Q_ASSERT(computerIndex < m_Computers.count());
Q_ASSERT(computerIndex >= 0 && computerIndex < m_Computers.count());
NvComputer* computer = m_Computers[computerIndex];
@@ -136,7 +136,7 @@ Session* ComputerModel::createSessionForCurrentGame(int computerIndex)
void ComputerModel::deleteComputer(int computerIndex)
{
Q_ASSERT(computerIndex < m_Computers.count());
Q_ASSERT(computerIndex >= 0 && computerIndex < m_Computers.count());
beginRemoveRows(QModelIndex(), computerIndex, computerIndex);
@@ -166,7 +166,7 @@ private:
void ComputerModel::wakeComputer(int computerIndex)
{
Q_ASSERT(computerIndex < m_Computers.count());
Q_ASSERT(computerIndex >= 0 && computerIndex < m_Computers.count());
DeferredWakeHostTask* wakeTask = new DeferredWakeHostTask(m_Computers[computerIndex]);
QThreadPool::globalInstance()->start(wakeTask);
@@ -174,7 +174,7 @@ void ComputerModel::wakeComputer(int computerIndex)
void ComputerModel::renameComputer(int computerIndex, QString name)
{
Q_ASSERT(computerIndex < m_Computers.count());
Q_ASSERT(computerIndex >= 0 && computerIndex < m_Computers.count());
m_ComputerManager->renameHost(m_Computers[computerIndex], name);
}
@@ -215,7 +215,7 @@ void ComputerModel::testConnectionForComputer(int)
void ComputerModel::pairComputer(int computerIndex, QString pin)
{
Q_ASSERT(computerIndex < m_Computers.count());
Q_ASSERT(computerIndex >= 0 && computerIndex < m_Computers.count());
m_ComputerManager->pairHost(m_Computers[computerIndex], pin);
}
+2 -2
View File
@@ -266,7 +266,7 @@ bool StreamUtils::getNativeDesktopMode(int displayIndex, SDL_DisplayMode* mode,
CGDirectDisplayID displayIds[MAX_DISPLAYS];
uint32_t displayCount = 0;
CGGetActiveDisplayList(MAX_DISPLAYS, displayIds, &displayCount);
if (displayIndex >= (int)displayCount) {
if (displayIndex < 0 || displayIndex >= (int)displayCount) {
return false;
}
@@ -343,7 +343,7 @@ bool StreamUtils::getNativeDesktopMode(int displayIndex, SDL_DisplayMode* mode,
#else
SDL_assert(SDL_WasInit(SDL_INIT_VIDEO));
if (displayIndex >= SDL_GetNumVideoDisplays()) {
if (displayIndex < 0 || displayIndex >= SDL_GetNumVideoDisplays()) {
return false;
}