Replace assert with bounds check and qFatal

This commit is contained in:
Nick Bolton 2024-07-30 00:04:57 +01:00
parent 6b803618e9
commit 7c40a4d198

View file

@ -33,13 +33,18 @@ ScreenSetupModel::ScreenSetupModel(
// bound rows and columns to prevent multiply overflow.
// this is unlikely to happen, as the grid size is only 3x9.
assert(m_NumColumns < 100 && m_NumRows < 100);
if (m_NumColumns * m_NumRows > screens.size())
if (m_NumColumns > 100 || m_NumRows > 100) {
qFatal(
"Not enough elements (%lld) in screens QList for %d columns and %d "
"rows",
screens.size(), m_NumColumns, m_NumRows);
"Grid size out of bounds: %d columns x %d rows", m_NumColumns,
m_NumRows);
return;
}
if (m_NumColumns * m_NumRows > screens.size()) {
qFatal(
"Scrren list (%lld) too small for %d columns x %d rows", screens.size(),
m_NumColumns, m_NumRows);
}
}
QVariant ScreenSetupModel::data(const QModelIndex &index, int role) const {