Fix potential self-move points

This commit is contained in:
Ion Gaztañaga
2022-08-21 02:19:44 +02:00
parent 19bb08cf17
commit 3a4cf45106
2 changed files with 6 additions and 3 deletions

View File

@ -175,6 +175,7 @@ void swap_and_update_key
{
if(begin != with){
::boost::adl_move_swap_ranges(begin, end, with);
if(key_next != key_range2) //Avoid potential self-swapping
::boost::adl_move_swap(*key_next, *key_range2);
if(key_next == key_mid){
key_mid = key_range2;
@ -217,6 +218,7 @@ RandIt2 buffer_and_update_key
while(begin != end) {
op(three_way_t(), begin++, with++, buffer++);
}
if (key_next != key_range2) //Avoid potential self-swapping
::boost::adl_move_swap(*key_next, *key_range2);
if (key_next == key_mid) {
key_mid = key_range2;

View File

@ -192,6 +192,7 @@ namespace pdqsort_detail {
// Put the pivot in the right place.
Iter pivot_pos = first - 1;
if(begin != pivot_pos) //Avoid potential self-move
*begin = boost::move(*pivot_pos);
*pivot_pos = boost::move(pivot);