QRecyclePool: fix potential UB

Return the pointer returned by placement new, not the pointer used as
input to placement new. There is a subtle difference and this grey
zone of the C++ standard is best avoided (keyword: std::launder()).

Change-Id: I27c159cdb29a5837120f3d44aa6c95da040fd1a2
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit 7381110745)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2023-06-26 11:00:56 +02:00 committed by Qt Cherry-pick Bot
parent 53708b055c
commit a3f7ec6acf
1 changed files with 3 additions and 6 deletions

View File

@ -96,8 +96,7 @@ template<typename T, int Step>
T *QRecyclePool<T, Step>::New()
{
T *rv = d->allocate();
new (rv) T;
return rv;
return new (rv) T;
}
template<typename T, int Step>
@ -105,8 +104,7 @@ template<typename T1>
T *QRecyclePool<T, Step>::New(const T1 &a)
{
T *rv = d->allocate();
new (rv) T(a);
return rv;
return new (rv) T(a);
}
template<typename T, int Step>
@ -114,8 +112,7 @@ template<typename T1>
T *QRecyclePool<T, Step>::New(T1 &a)
{
T *rv = d->allocate();
new (rv) T(a);
return rv;
return new (rv) T(a);
}
template<typename T, int Step>