1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:07:44 +00:00

AK: Return early from swap() when swapping the same object

When swapping the same object, we could end up with a double-free error.
This was found while quick-sorting a Vector of Variants holding complex
types, reproduced by the new swap_same_complex_object test case.
This commit is contained in:
Timothy Flynn 2021-08-28 11:19:21 -04:00 committed by Linus Groh
parent aa2e19e58f
commit 587d4663a3
3 changed files with 59 additions and 0 deletions

View file

@ -99,6 +99,8 @@ constexpr T ceil_div(T a, U b)
template<typename T, typename U>
inline void swap(T& a, U& b)
{
if (&a == &b)
return;
U tmp = move((U&)a);
a = (T &&) move(b);
b = move(tmp);