On 29 April 2016 at 11:18, Rick Walsh <[email protected]> wrote: > > diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp > index 6e0abf0..350d15a 100644 > --- a/qt-models/cylindermodel.cpp > +++ b/qt-models/cylindermodel.cpp > @@ -274,7 +274,7 @@ bool CylindersModel::setData(const QModelIndex &index, > const QVariant &value, in > case USE: > if (CHANGED()) { > int use = vString.toInt(); > - if (use > NUM_GAS_USE - 1) > + if (use > NUM_GAS_USE - 1 || use < 0) > use = 0; > cyl->cylinder_use = (enum cylinderuse)use; > changed = true; >
our clamp on the backend isn't optimal as the UI seems a bit broken. the user has no idea what to write in that field... at least with this patch, it won't read random adjacent memory (attached). >> > but it's probably a good thing to also limit the user on the UI side - >> > i.e. once a bad value is entered that field should be auto-adjusted to >> > a good value. >> > >> Agreed. I think this should be a drop-down list. Or remove the field from >> the table entirely. I couldn't work out if/how it's used at all. >> i've spent some time today, trying to make this into a combobox like the one in the "Type" column, but i'm giving up as it doesn't work for some reason... BTW, there is something fishy about the item delegate used for the "Use" column, as the source code reads that it's supposed to be a combobox, already! for now, i suggest that you file a bug report in the tracker. lubomir --
From 8a0daf763e136ec309ebcfe83991edd325ac07bc Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" <[email protected]> Date: Thu, 28 Apr 2016 17:33:05 +0300 Subject: [PATCH] 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 <[email protected]> --- qt-models/cylindermodel.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp index b1ce0be..350d15a 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; -- 1.7.11.msysgit.0
_______________________________________________ subsurface mailing list [email protected] http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
