QVarLengthArray: protect against aliasing in resize(n, t)

Amends a00a1d8806.

Pick-to: 6.5 6.4
Change-Id: I3fa6183466715555530d4042006049e286897343
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Marc Mutz 2023-02-16 08:25:40 +01:00
parent af233cb969
commit 0cfaa6e896

View File

@ -218,6 +218,10 @@ protected:
void reallocate_impl(qsizetype prealloc, void *array, qsizetype size, qsizetype alloc);
void resize_impl(qsizetype prealloc, void *array, qsizetype sz, const T &v)
{
if (QtPrivate::q_points_into_range(&v, begin(), end())) {
resize_impl(prealloc, array, sz, T(v));
return;
}
reallocate_impl(prealloc, array, sz, qMax(sz, capacity()));
while (size() < sz) {
q20::construct_at(data() + size(), v);