Skip to content

Commit 34893eb

Browse files
ilaripihartoj
authored andcommitted
fix compiler warning about writing to a region of size 0
1 parent ab0c9e1 commit 34893eb

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

projects/gui/src/newtournamentdialog.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
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

216215
void 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
}

0 commit comments

Comments
 (0)