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>
This commit is contained in:
Lubomir I. Ivanov 2016-04-28 17:33:05 +03:00 committed by Dirk Hohndel
parent 56ed3f1c61
commit cae99471ad

View file

@ -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;