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>
This commit is contained in:
Dirk Hohndel 2019-10-26 17:16:09 -04:00
parent d3d51b175d
commit 4f9783ff60

View file

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