mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
filter: use 64-bit integer literal for generating bit fields
For multiple-choice constraints we use a bit field of type uint64_t. This means we theoretically support up to 64 items. Currently use at most seven. Coverity complained (correctly) that we use the expression "1 << x" to generate the bitfields. However 1 is a 32-bit literal on most platforms, which makes this undefined behavior for x >= 32. Change the integer literal to 64-bit 1ULL. Moreover, when detecting items with an index >= 64, don't even attempt to set the according bit, since this is undefined behavior and the compiler is free to do as it pleases in such a case. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
b984839836
commit
e7b56c2d31
2 changed files with 6 additions and 4 deletions
|
@ -1059,7 +1059,7 @@ static bool check_year_range(const filter_constraint &c, const struct dive *d)
|
|||
|
||||
static bool check_multiple_choice(const filter_constraint &c, int v)
|
||||
{
|
||||
bool has_bit = c.data.multiple_choice & (1 << v);
|
||||
bool has_bit = c.data.multiple_choice & (1ULL << v);
|
||||
return has_bit != c.negate;
|
||||
}
|
||||
|
||||
|
|
|
@ -324,7 +324,7 @@ void FilterConstraintWidget::update()
|
|||
if (multipleChoice) {
|
||||
uint64_t bits = idx.data(FilterConstraintModel::MULTIPLE_CHOICE_ROLE).value<uint64_t>();
|
||||
for (int i = 0; i < multipleChoice->count(); ++i)
|
||||
multipleChoice->item(i)->setSelected(bits & (1 << i));
|
||||
multipleChoice->item(i)->setSelected(bits & (1ULL << i));
|
||||
}
|
||||
|
||||
// Update the unit strings in case the locale was changed
|
||||
|
@ -392,9 +392,11 @@ void FilterConstraintWidget::multipleChoiceEdited()
|
|||
uint64_t bits = 0;
|
||||
for (const QModelIndex &idx: multipleChoice->selectionModel()->selectedIndexes()) {
|
||||
int row = idx.row();
|
||||
if (row >= 64)
|
||||
if (row >= 64) {
|
||||
qWarning("FilterConstraint: multiple-choice with more than 64 entries not supported");
|
||||
bits |= 1 << row;
|
||||
continue;
|
||||
}
|
||||
bits |= 1ULL << row;
|
||||
}
|
||||
QModelIndex idx = model->index(row, 0);
|
||||
model->setData(idx, qulonglong(bits), FilterConstraintModel::MULTIPLE_CHOICE_ROLE);
|
||||
|
|
Loading…
Reference in a new issue