aboutsummaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2019-10-26 17:16:09 -0400
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-10-26 19:17:53 -0700
commit4f9783ff606081baec1926676bd048e99e00e578 (patch)
tree17fa728a76754e60161ca8386cd9f855a94c3765 /qt-models
parentd3d51b175dd39722e58b7315009a5fff1b000260 (diff)
downloadsubsurface-4f9783ff606081baec1926676bd048e99e00e578.tar.gz
Cleanup: avoid out of bounds access
This is extremely unlikely to ever happen since we reserve space for a hundred weight models, but hey, doing this right is quite easy, so let's fix it. Found by Coverity. Fixes CID #350117 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/weightmodel.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/qt-models/weightmodel.cpp b/qt-models/weightmodel.cpp
index 3295e29ae..715af1571 100644
--- a/qt-models/weightmodel.cpp
+++ b/qt-models/weightmodel.cpp
@@ -99,13 +99,13 @@ bool WeightModel::setData(const QModelIndex &index, const QVariant &value, int r
if (!ws->description || gettextFromC::tr(ws->description) != vString) {
// loop over translations to see if one matches
int i = -1;
- while (ws_info[++i].name && i < MAX_WS_INFO) {
+ while (i < MAX_WS_INFO && ws_info[++i].name) {
if (gettextFromC::tr(ws_info[i].name) == vString) {
ws->description = copy_string(ws_info[i].name);
break;
}
}
- if (ws_info[i].name == NULL) // didn't find a match
+ if (i == MAX_WS_INFO || ws_info[i].name == NULL) // didn't find a match
ws->description = copy_qstring(vString);
changed = true;
}