Skip to content

Commit 49d7ff2

Browse files
committed
fix: segmentation fault with empty sets of clusters
regression introduced with commit 045a6d5 (Jun 15 21:25:02 2024 +0200) very easy to test, but sadly not yet covered by our test-suite: ```sh vsearch --cluster_unoise <(printf ">s\nAA\n") --blast6out - ``` cause: std::minmax_element() and std::max_element() return non-deferencable iterators when the searched container is empty.
1 parent 57f67e8 commit 49d7ff2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/cluster.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1396,13 +1396,13 @@ auto cluster(char * dbname,
13961396

13971397
auto const minmax_elements = std::minmax_element(cluster_abundance_v.cbegin(),
13981398
cluster_abundance_v.cend());
1399-
auto const abundance_min = *std::get<0>(minmax_elements);
1400-
auto const abundance_max = *std::get<1>(minmax_elements);
1399+
auto const abundance_min = cluster_abundance_v.empty() ? 0 : *std::get<0>(minmax_elements);
1400+
auto const abundance_max = cluster_abundance_v.empty() ? 0 : *std::get<1>(minmax_elements);
14011401
int const singletons = std::count(cluster_abundance_v.cbegin(),
14021402
cluster_abundance_v.cend(), int64_t{1});
14031403
auto const max_element = std::max_element(cluster_size.cbegin(),
14041404
cluster_size.cend());
1405-
auto const size_max = *max_element;
1405+
auto const size_max = cluster_size.empty() ? 0 : *max_element;
14061406

14071407

14081408
/* Sort sequences in clusters by their abundance or ordinal number */

0 commit comments

Comments
 (0)