Skip to content

Commit c5a8eb5

Browse files
authored
Merge pull request #3307 from eseiler/fix/codeql
[FIX] CodeQL reports
2 parents 6f38aac + 18e5ddb commit c5a8eb5

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

include/seqan3/search/detail/search_scheme_algorithm.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ inline auto search_scheme_block_info(search_scheme_t const & search_scheme, size
244244
for (uint8_t block_id = 0; block_id < rest; ++block_id)
245245
++blocks_length[block_id];
246246

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

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

786-
for (uint8_t search_id = 0; search_id < search_scheme.size(); ++search_id)
786+
for (size_t search_id = 0; search_id < search_scheme.size(); ++search_id)
787787
{
788788
auto const & search = search_scheme[search_id];
789789
auto const & [blocks_length, start_pos] = block_info[search_id];

include/seqan3/search/fm_index/bi_fm_index_cursor.hpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ class bi_fm_index_cursor
335335

336336
size_type new_parent_lb = fwd_lb, new_parent_rb = fwd_rb;
337337

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

355-
_last_char = c;
355+
assert(c <= std::numeric_limits<sdsl_char_type>::max());
356+
_last_char = static_cast<sdsl_char_type>(c);
356357
++depth;
357358

358359
return true;
@@ -387,7 +388,7 @@ class bi_fm_index_cursor
387388

388389
size_type new_parent_lb = rev_lb, new_parent_rb = rev_rb;
389390

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

407-
_last_char = c;
408+
assert(c <= std::numeric_limits<sdsl_char_type>::max());
409+
_last_char = static_cast<sdsl_char_type>(c);
408410
++depth;
409411

410412
return true;
@@ -685,7 +687,7 @@ class bi_fm_index_cursor
685687

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

688-
sdsl_char_type c = _last_char + 1;
690+
sdsl_sigma_type c = _last_char + 1;
689691

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

703705
if (c != sigma)
704706
{
705-
_last_char = c;
707+
assert(c <= std::numeric_limits<sdsl_char_type>::max());
708+
_last_char = static_cast<sdsl_char_type>(c);
706709

707710
return true;
708711
}
@@ -744,7 +747,7 @@ class bi_fm_index_cursor
744747

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

747-
sdsl_char_type c = _last_char + 1;
750+
sdsl_sigma_type c = _last_char + 1;
748751
while (c < sigma
749752
&& !bidirectional_search_cycle(index->rev_fm.index,
750753
index->rev_fm.index.comp2char[c],
@@ -760,7 +763,8 @@ class bi_fm_index_cursor
760763

761764
if (c != sigma)
762765
{
763-
_last_char = c;
766+
assert(c <= std::numeric_limits<sdsl_char_type>::max());
767+
_last_char = static_cast<sdsl_char_type>(c);
764768

765769
return true;
766770
}

include/seqan3/search/fm_index/fm_index_cursor.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class fm_index_cursor
260260
// store all cursors at once in a private std::array of cursors
261261
assert(index != nullptr);
262262

263-
sdsl_char_type c = 1; // NOTE: start with 0 or 1 depending on implicit_sentintel
263+
sdsl_sigma_type c = 1; // NOTE: start with 0 or 1 depending on implicit_sentintel
264264
size_type _lb = node.lb, _rb = node.rb;
265265
while (c < sigma && !backward_search(index->index, index->index.comp2char[c], _lb, _rb))
266266
{
@@ -271,7 +271,8 @@ class fm_index_cursor
271271
{
272272
parent_lb = node.lb;
273273
parent_rb = node.rb;
274-
node = {_lb, _rb, node.depth + 1, c};
274+
assert(c <= std::numeric_limits<sdsl_char_type>::max());
275+
node = {_lb, _rb, node.depth + 1, static_cast<sdsl_char_type>(c)};
275276
return true;
276277
}
277278
return false;
@@ -406,7 +407,7 @@ class fm_index_cursor
406407
// parent_lb > parent_rb --> invalid interval
407408
assert(parent_lb <= parent_rb);
408409

409-
sdsl_char_type c = node.last_char + 1;
410+
sdsl_sigma_type c = node.last_char + 1;
410411
size_type _lb = parent_lb, _rb = parent_rb;
411412

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

417418
if (c != sigma) // Collection has additional sentinel as delimiter
418419
{
419-
node = {_lb, _rb, node.depth, c};
420+
assert(c <= std::numeric_limits<sdsl_char_type>::max());
421+
node = {_lb, _rb, node.depth, static_cast<sdsl_char_type>(c)};
420422
return true;
421423
}
422424
return false;

test/unit/utility/math_test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ TYPED_TEST(unsigned_operations, floor_log2)
2525
constexpr size_t one2 = seqan3::detail::floor_log2<unsigned_t>(0b0011);
2626
constexpr size_t two1 = seqan3::detail::floor_log2<unsigned_t>(0b0101);
2727
constexpr size_t two2 = seqan3::detail::floor_log2<unsigned_t>(0b0111);
28-
constexpr size_t seven = seqan3::detail::floor_log2<unsigned_t>(0b10010010);
28+
constexpr size_t seven = seqan3::detail::floor_log2<unsigned_t>(0b1001'0010);
2929
EXPECT_EQ(zero, 0u);
3030
EXPECT_EQ(one1, 1u);
3131
EXPECT_EQ(one2, 1u);
@@ -36,8 +36,8 @@ TYPED_TEST(unsigned_operations, floor_log2)
3636
for (uint8_t log2_value = 0; log2_value < seqan3::detail::bits_of<unsigned_t>; ++log2_value)
3737
{
3838
unsigned_t start = unsigned_t{1u} << log2_value;
39-
unsigned_t end = start << 1u;
40-
for (unsigned_t n = start, k = 0u; n < end && k < max_iterations; ++n, ++k)
39+
unsigned_t end = static_cast<unsigned_t>(std::min<size_t>(start, max_iterations) + start);
40+
for (unsigned_t n = start; n < end; ++n)
4141
{
4242
EXPECT_EQ(seqan3::detail::floor_log2(n), log2_value);
4343
EXPECT_EQ(std::floor(std::log2(n)), log2_value) << "If this fails this might be a floating point rounding "
@@ -54,7 +54,7 @@ TYPED_TEST(unsigned_operations, ceil_log2)
5454
constexpr size_t two = seqan3::detail::ceil_log2<unsigned_t>(0b0011);
5555
constexpr size_t three1 = seqan3::detail::ceil_log2<unsigned_t>(0b0101);
5656
constexpr size_t three2 = seqan3::detail::ceil_log2<unsigned_t>(0b0111);
57-
constexpr size_t eight = seqan3::detail::ceil_log2<unsigned_t>(0b10010010);
57+
constexpr size_t eight = seqan3::detail::ceil_log2<unsigned_t>(0b1001'0010);
5858
EXPECT_EQ(zero, 0u);
5959
EXPECT_EQ(one, 1u);
6060
EXPECT_EQ(two, 2u);
@@ -65,13 +65,13 @@ TYPED_TEST(unsigned_operations, ceil_log2)
6565
for (uint8_t log2_value = 0; log2_value < seqan3::detail::bits_of<unsigned_t>; ++log2_value)
6666
{
6767
unsigned_t start = unsigned_t{1u} << log2_value;
68-
unsigned_t end = start << 1u;
68+
unsigned_t end = static_cast<unsigned_t>(std::min<size_t>(start, max_iterations) + start);
6969
EXPECT_EQ(seqan3::detail::ceil_log2(start), log2_value);
7070
EXPECT_EQ(std::ceil(std::log2(start)), log2_value) << "ceil_log2 of " << start << " should be " << log2_value
7171
<< "; If this fails this might be a floating point rounding "
7272
<< "error on your machine.";
7373

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

0 commit comments

Comments
 (0)