divelist: prevent a crash for missing column width

The `static int defaultWidth[]` definition in divelistview.cpp
could potentially end up missing an element which can later result
in out-of-bounds access when iterating through the list of
columns and updating their widths.

Add a couple of methods in DiveTripModel for setting and getting
the widths and use those. The default values are now pre-set in a
QVector in the DiveTripModel() constructor.

Throw warnings if out-of-bounds columns are requested.

Reported-by: Gaetan Bisson <bisson@archlinux.org>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
Lubomir I. Ivanov 2017-10-03 23:16:15 +03:00 committed by Dirk Hohndel
parent 53c1c3f26b
commit e3118d915c
4 changed files with 40 additions and 8 deletions

View file

@ -94,10 +94,13 @@ public:
DiveTripModel(QObject *parent = 0);
Layout layout() const;
void setLayout(Layout layout);
int columnWidth(int column);
void setColumnWidth(int column, int width);
private:
void setupModelData();
QMap<dive_trip_t *, TripItem *> trips;
QVector<int> columnWidthMap;
Layout currentLayout;
};