File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed
Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change 2121#include < QFileDialog>
2222#include < QSettings>
2323#include < QMenu>
24- #include < functional>
2524#include < algorithm>
2625
2726#include < board/boardfactory.h>
@@ -215,17 +214,31 @@ void NewTournamentDialog::configureEngine(const QModelIndex& index)
215214
216215void NewTournamentDialog::moveEngine (int offset)
217216{
217+ if (offset == 0 )
218+ return ;
219+
218220 QModelIndex index (ui->m_playersList ->currentIndex ());
219221 int row1 = index.row ();
220222 int row2 = row1 + offset;
221- EngineConfiguration tmp (m_addedEnginesManager->engineAt (row1));
222- TimeControl tc = m_timeControls.at (row1);
223223
224+ // It should be impossible for either row to be out of bounds,
225+ // but we'll check it explicitly, which makes the compiler happy.
226+ if (row1 < 0 || row1 >= m_timeControls.size ())
227+ {
228+ qWarning (" row1 out of bounds" );
229+ return ;
230+ }
231+ if (row2 < 0 || row2 >= m_timeControls.size ())
232+ {
233+ qWarning (" row2 out of bounds" );
234+ return ;
235+ }
236+
237+ EngineConfiguration tmp (m_addedEnginesManager->engineAt (row1));
224238 m_addedEnginesManager->updateEngineAt (row1, m_addedEnginesManager->engineAt (row2));
225239 m_addedEnginesManager->updateEngineAt (row2, tmp);
226240
227- m_timeControls[row1] = m_timeControls.at (row2);
228- m_timeControls[row2]= tc;
241+ m_timeControls.swapItemsAt (row1, row2);
229242
230243 ui->m_playersList ->setCurrentIndex (index.sibling (row2, 0 ));
231244}
You can’t perform that action at this time.
0 commit comments