From e7b56c2d315c31ec64696dbaca9550071633aef4 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 25 Oct 2020 23:01:03 +0100 Subject: 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 --- core/filterconstraint.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/filterconstraint.cpp b/core/filterconstraint.cpp index 6922f1530..54654457f 100644 --- a/core/filterconstraint.cpp +++ b/core/filterconstraint.cpp @@ -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; } -- cgit v1.2.3-70-g09d2