aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/libstdc++-v3/include/bits/stl_algo.h
diff options
context:
space:
mode:
Diffstat (limited to 'gcc-4.9/libstdc++-v3/include/bits/stl_algo.h')
-rw-r--r--gcc-4.9/libstdc++-v3/include/bits/stl_algo.h16
1 files changed, 13 insertions, 3 deletions
diff --git a/gcc-4.9/libstdc++-v3/include/bits/stl_algo.h b/gcc-4.9/libstdc++-v3/include/bits/stl_algo.h
index 104ab8685..40233c58f 100644
--- a/gcc-4.9/libstdc++-v3/include/bits/stl_algo.h
+++ b/gcc-4.9/libstdc++-v3/include/bits/stl_algo.h
@@ -3629,7 +3629,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Efficiently compare identical prefixes: O(N) if sequences
// have the same elements in the same order.
- for (; __first1 != __last1; ++__first1, ++__first2)
+ for (; __first1 != __last1 && __first2 != __last2;
+ ++__first1, ++__first2)
if (!__pred(__first1, __first2))
break;
@@ -4464,7 +4465,12 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
if (__first != __last)
for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
- std::iter_swap(__i, __first + (std::rand() % ((__i - __first) + 1)));
+ {
+ _RandomAccessIterator __j = __first
+ + std::rand() % ((__i - __first) + 1);
+ if (__i != __j)
+ std::iter_swap(__i, __j);
+ }
}
/**
@@ -4498,7 +4504,11 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
if (__first == __last)
return;
for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
- std::iter_swap(__i, __first + __rand((__i - __first) + 1));
+ {
+ _RandomAccessIterator __j = __first + __rand((__i - __first) + 1);
+ if (__i != __j)
+ std::iter_swap(__i, __j);
+ }
}