diff options
author | Lubomir I. Ivanov <neolit123@gmail.com> | 2016-04-28 17:33:05 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-04-29 09:07:59 -0700 |
commit | cae99471adc7532db34c365ee729a1ea7ffea204 (patch) | |
tree | d89c4c075bad87bda4da440b7cad3385b575bcad /qt-models | |
parent | 56ed3f1c6119b9ac86f602455d54318623640056 (diff) | |
download | subsurface-cae99471adc7532db34c365ee729a1ea7ffea204.tar.gz |
CylindersModel: clamp the "cylinderuse" values
If the value for "use" is negative or larger than the number of
elements in "enum cylinderuse", later CylindersModel::data() can
request a string in the lines of cylinderuse_text[cyl->cylinder_use],
which can SIGSEGV.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-models')
-rw-r--r-- | qt-models/cylindermodel.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp index b1ce0be24..350d15aa4 100644 --- a/qt-models/cylindermodel.cpp +++ b/qt-models/cylindermodel.cpp @@ -273,7 +273,10 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in break; case USE: if (CHANGED()) { - cyl->cylinder_use = (enum cylinderuse)vString.toInt(); + int use = vString.toInt(); + if (use > NUM_GAS_USE - 1 || use < 0) + use = 0; + cyl->cylinder_use = (enum cylinderuse)use; changed = true; } break; |