diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2021-02-09 14:03:04 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-02-11 10:30:03 +0000 |
commit | 249b3100466556ff56f04fbf063f977dbdccbda3 (patch) | |
tree | a242bd172b8468bcccb61288a914de8a11265bc1 /src/corelib | |
parent | 98e9275112b4fc1dba6706a96b955a0230518ef6 (diff) |
Restore pre-Qt6 QList::fill() behavior
Somehow QList::fill(t, newSize) introduced a regression in Qt6:
when newSize < QList::size() we should resize to the newSize.
This is aligned with QVector::fill() in 5.15 and std::vector::assign()
While 6.0 is already out, picking it to 6.0.x could save someone who
haven't migrated yet as well as fix some accidental bugs in Qt's code
[ChangeLog][QtCore][QList] Fixed QList::fill() regression introduced in
6.0: calling fill() with size < current list size wouldn't truncate the
list
Fixes: QTBUG-91042
Change-Id: Ic166e2c5e42390b61df1030f7c705e344433f7f2
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
(cherry picked from commit 6512a7fc642c65455db770385c67cfa6d71c294c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qlist.h | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 517ba10326..311ca43637 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -845,8 +845,11 @@ inline QList<T> &QList<T>::fill(parameter_type t, qsizetype newSize) // we're detached const T copy(t); d->assign(d.begin(), d.begin() + qMin(size(), newSize), t); - if (newSize > size()) + if (newSize > size()) { d->copyAppend(newSize - size(), copy); + } else if (newSize < size()) { + d->truncate(newSize); + } } return *this; } |