Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] CodeQL reports #3307

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/seqan3/search/detail/search_scheme_algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ inline auto search_scheme_block_info(search_scheme_t const & search_scheme, size
for (uint8_t block_id = 0; block_id < rest; ++block_id)
++blocks_length[block_id];

for (uint8_t search_id = 0; search_id < search_scheme.size(); ++search_id)
for (size_t search_id = 0; search_id < search_scheme.size(); ++search_id)
{
auto const & search = search_scheme[search_id];

Expand Down Expand Up @@ -783,7 +783,7 @@ inline void search_ss(index_t const & index,
// retrieve cumulative block lengths and starting position
auto const block_info = search_scheme_block_info(search_scheme, std::ranges::size(query));

for (uint8_t search_id = 0; search_id < search_scheme.size(); ++search_id)
for (size_t search_id = 0; search_id < search_scheme.size(); ++search_id)
{
auto const & search = search_scheme[search_id];
auto const & [blocks_length, start_pos] = block_info[search_id];
Expand Down
20 changes: 12 additions & 8 deletions include/seqan3/search/fm_index/bi_fm_index_cursor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class bi_fm_index_cursor

size_type new_parent_lb = fwd_lb, new_parent_rb = fwd_rb;

sdsl_char_type c = 1; // NOTE: start with 0 or 1 depending on implicit_sentintel
sdsl_sigma_type c = 1; // NOTE: start with 0 or 1 depending on implicit_sentintel
while (c < sigma
&& !bidirectional_search(index->fwd_fm.index,
index->fwd_fm.index.comp2char[c],
Expand All @@ -352,7 +352,8 @@ class bi_fm_index_cursor
parent_lb = new_parent_lb;
parent_rb = new_parent_rb;

_last_char = c;
assert(c <= std::numeric_limits<sdsl_char_type>::max());
_last_char = static_cast<sdsl_char_type>(c);
++depth;

return true;
Expand Down Expand Up @@ -387,7 +388,7 @@ class bi_fm_index_cursor

size_type new_parent_lb = rev_lb, new_parent_rb = rev_rb;

sdsl_char_type c = 1; // NOTE: start with 0 or 1 depending on implicit_sentintel
sdsl_sigma_type c = 1; // NOTE: start with 0 or 1 depending on implicit_sentintel
while (c < sigma
&& !bidirectional_search(index->rev_fm.index,
index->rev_fm.index.comp2char[c],
Expand All @@ -404,7 +405,8 @@ class bi_fm_index_cursor
parent_lb = new_parent_lb;
parent_rb = new_parent_rb;

_last_char = c;
assert(c <= std::numeric_limits<sdsl_char_type>::max());
_last_char = static_cast<sdsl_char_type>(c);
++depth;

return true;
Expand Down Expand Up @@ -685,7 +687,7 @@ class bi_fm_index_cursor

assert(index != nullptr && query_length() > 0);

sdsl_char_type c = _last_char + 1;
sdsl_sigma_type c = _last_char + 1;

while (c < sigma
&& !bidirectional_search_cycle(index->fwd_fm.index,
Expand All @@ -702,7 +704,8 @@ class bi_fm_index_cursor

if (c != sigma)
{
_last_char = c;
assert(c <= std::numeric_limits<sdsl_char_type>::max());
_last_char = static_cast<sdsl_char_type>(c);

return true;
}
Expand Down Expand Up @@ -744,7 +747,7 @@ class bi_fm_index_cursor

assert(index != nullptr && query_length() > 0);

sdsl_char_type c = _last_char + 1;
sdsl_sigma_type c = _last_char + 1;
while (c < sigma
&& !bidirectional_search_cycle(index->rev_fm.index,
index->rev_fm.index.comp2char[c],
Expand All @@ -760,7 +763,8 @@ class bi_fm_index_cursor

if (c != sigma)
{
_last_char = c;
assert(c <= std::numeric_limits<sdsl_char_type>::max());
_last_char = static_cast<sdsl_char_type>(c);

return true;
}
Expand Down
10 changes: 6 additions & 4 deletions include/seqan3/search/fm_index/fm_index_cursor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class fm_index_cursor
// store all cursors at once in a private std::array of cursors
assert(index != nullptr);

sdsl_char_type c = 1; // NOTE: start with 0 or 1 depending on implicit_sentintel
sdsl_sigma_type c = 1; // NOTE: start with 0 or 1 depending on implicit_sentintel
size_type _lb = node.lb, _rb = node.rb;
while (c < sigma && !backward_search(index->index, index->index.comp2char[c], _lb, _rb))
{
Expand All @@ -271,7 +271,8 @@ class fm_index_cursor
{
parent_lb = node.lb;
parent_rb = node.rb;
node = {_lb, _rb, node.depth + 1, c};
assert(c <= std::numeric_limits<sdsl_char_type>::max());
node = {_lb, _rb, node.depth + 1, static_cast<sdsl_char_type>(c)};
return true;
}
return false;
Expand Down Expand Up @@ -406,7 +407,7 @@ class fm_index_cursor
// parent_lb > parent_rb --> invalid interval
assert(parent_lb <= parent_rb);

sdsl_char_type c = node.last_char + 1;
sdsl_sigma_type c = node.last_char + 1;
size_type _lb = parent_lb, _rb = parent_rb;

while (c < sigma && !backward_search(index->index, index->index.comp2char[c], _lb, _rb))
Expand All @@ -416,7 +417,8 @@ class fm_index_cursor

if (c != sigma) // Collection has additional sentinel as delimiter
{
node = {_lb, _rb, node.depth, c};
assert(c <= std::numeric_limits<sdsl_char_type>::max());
node = {_lb, _rb, node.depth, static_cast<sdsl_char_type>(c)};
return true;
}
return false;
Expand Down
12 changes: 6 additions & 6 deletions test/unit/utility/math_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ TYPED_TEST(unsigned_operations, floor_log2)
constexpr size_t one2 = seqan3::detail::floor_log2<unsigned_t>(0b0011);
constexpr size_t two1 = seqan3::detail::floor_log2<unsigned_t>(0b0101);
constexpr size_t two2 = seqan3::detail::floor_log2<unsigned_t>(0b0111);
constexpr size_t seven = seqan3::detail::floor_log2<unsigned_t>(0b10010010);
constexpr size_t seven = seqan3::detail::floor_log2<unsigned_t>(0b1001'0010);
EXPECT_EQ(zero, 0u);
EXPECT_EQ(one1, 1u);
EXPECT_EQ(one2, 1u);
Expand All @@ -36,8 +36,8 @@ TYPED_TEST(unsigned_operations, floor_log2)
for (uint8_t log2_value = 0; log2_value < seqan3::detail::bits_of<unsigned_t>; ++log2_value)
{
unsigned_t start = unsigned_t{1u} << log2_value;
unsigned_t end = start << 1u;
for (unsigned_t n = start, k = 0u; n < end && k < max_iterations; ++n, ++k)
unsigned_t end = static_cast<unsigned_t>(std::min<size_t>(start, max_iterations) + start);
for (unsigned_t n = start; n < end; ++n)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be something wrong here.
end = start * 2
but also the result of std::min seems wrong:
I expeected something like:
std::min(start, max_iterations) + start

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was very wrong 😆

{
EXPECT_EQ(seqan3::detail::floor_log2(n), log2_value);
EXPECT_EQ(std::floor(std::log2(n)), log2_value) << "If this fails this might be a floating point rounding "
Expand All @@ -54,7 +54,7 @@ TYPED_TEST(unsigned_operations, ceil_log2)
constexpr size_t two = seqan3::detail::ceil_log2<unsigned_t>(0b0011);
constexpr size_t three1 = seqan3::detail::ceil_log2<unsigned_t>(0b0101);
constexpr size_t three2 = seqan3::detail::ceil_log2<unsigned_t>(0b0111);
constexpr size_t eight = seqan3::detail::ceil_log2<unsigned_t>(0b10010010);
constexpr size_t eight = seqan3::detail::ceil_log2<unsigned_t>(0b1001'0010);
EXPECT_EQ(zero, 0u);
EXPECT_EQ(one, 1u);
EXPECT_EQ(two, 2u);
Expand All @@ -65,13 +65,13 @@ TYPED_TEST(unsigned_operations, ceil_log2)
for (uint8_t log2_value = 0; log2_value < seqan3::detail::bits_of<unsigned_t>; ++log2_value)
{
unsigned_t start = unsigned_t{1u} << log2_value;
unsigned_t end = start << 1u;
unsigned_t end = static_cast<unsigned_t>(std::min<size_t>(start, max_iterations) + start);
EXPECT_EQ(seqan3::detail::ceil_log2(start), log2_value);
EXPECT_EQ(std::ceil(std::log2(start)), log2_value) << "ceil_log2 of " << start << " should be " << log2_value
<< "; If this fails this might be a floating point rounding "
<< "error on your machine.";

for (unsigned_t n = start + 1u, k = 0u; n < end && k < max_iterations; ++n, ++k)
for (unsigned_t n = start + 1u; n < end; ++n)
{
EXPECT_EQ(seqan3::detail::ceil_log2(n), log2_value + 1u);

Expand Down
Loading