From c283a2f12395df0d8e40b965b116e8df7e7bb7f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Wed, 24 Apr 2019 20:59:00 +0200 Subject: [PATCH] Fixes #26 ("Invalid iterator increment/decrement in the last iteration of adaptive_sort_combine_blocks") --- doc/move.qbk | 7 +++++++ include/boost/move/algo/adaptive_sort.hpp | 10 ++++++++-- include/boost/move/algo/detail/set_difference.hpp | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/doc/move.qbk b/doc/move.qbk index 413fafe..e7a3be0 100644 --- a/doc/move.qbk +++ b/doc/move.qbk @@ -802,6 +802,13 @@ Special thanks to: [section:release_notes Release Notes] +[section:release_notes_boost_1_71 Boost 1.71 Release] + +* Fixed bugs: + * [@https://github.com/boostorg/move/issues/26 Git Issue #26: ['"Invalid iterator increment/decrement in the last iteration of adaptive_sort_combine_blocks"]]. + +[endsect] + [section:release_notes_boost_1_70 Boost 1.70 Release] * Removed support for deprecated GCC compilers. diff --git a/include/boost/move/algo/adaptive_sort.hpp b/include/boost/move/algo/adaptive_sort.hpp index 5819399..cdffa2e 100644 --- a/include/boost/move/algo/adaptive_sort.hpp +++ b/include/boost/move/algo/adaptive_sort.hpp @@ -180,7 +180,7 @@ void adaptive_sort_combine_blocks size_type const max_i = n_reg_combined + (l_irreg_combined != 0); if(merge_left || !use_buf) { - for( size_type combined_i = 0; combined_i != max_i; ++combined_i, combined_first += l_reg_combined) { + for( size_type combined_i = 0; combined_i != max_i; ) { //Now merge blocks bool const is_last = combined_i==n_reg_combined; size_type const l_cur_combined = is_last ? l_irreg_combined : l_reg_combined; @@ -202,11 +202,15 @@ void adaptive_sort_combine_blocks (keys, key_comp, combined_first, l_block, 0u, n_block_a, n_block_b, l_irreg2, comp, xbuf_used); } BOOST_MOVE_ADAPTIVE_SORT_PRINT_L2(" After merge_blocks_L: ", len + l_block); + ++combined_i; + if(combined_i != max_i) + combined_first += l_reg_combined; } } else{ combined_first += l_reg_combined*(max_i-1); - for( size_type combined_i = max_i; combined_i--; combined_first -= l_reg_combined) { + for( size_type combined_i = max_i; combined_i; ) { + --combined_i; bool const is_last = combined_i==n_reg_combined; size_type const l_cur_combined = is_last ? l_irreg_combined : l_reg_combined; @@ -222,6 +226,8 @@ void adaptive_sort_combine_blocks merge_blocks_right (keys, key_comp, combined_first, l_block, n_block_a, n_block_b, l_irreg2, comp, xbuf_used); BOOST_MOVE_ADAPTIVE_SORT_PRINT_L2(" After merge_blocks_R: ", len + l_block); + if(combined_i) + combined_first -= l_reg_combined; } } } diff --git a/include/boost/move/algo/detail/set_difference.hpp b/include/boost/move/algo/detail/set_difference.hpp index 51d0475..c988294 100644 --- a/include/boost/move/algo/detail/set_difference.hpp +++ b/include/boost/move/algo/detail/set_difference.hpp @@ -174,7 +174,7 @@ ForwardOutputIt1 inplace_set_unique_difference ++first2; } else if (comp(*first1, *first2)){ - //skip any adjacent equivalent elementin range 1 + //skip any adjacent equivalent element in range 1 ForwardOutputIt1 result = first1; if (++first1 != last1 && !comp(*result, *first1)) { //Some elements from range 1 must be skipped, no longer an inplace operation