diff options
author | Marc Mutz <marc.mutz@qt.io> | 2021-12-07 17:46:26 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2021-12-08 16:39:27 +0000 |
commit | d4a88e4ea4dd0d24c9c43553dd4c48a79635803c (patch) | |
tree | 2c31d0b6c2203a718e0f247e7d09baba046d5661 /src | |
parent | 0f88e79ed80aaf3c02def55c6d507dde17eada60 (diff) |
QVarLengthArray: fix size update on failed append()
If the in-place constructor throws, the old code had already updated
the container's size(). Fix by delaying the update to after the
in-place construction.
[ChangeLog][QtCore][QVarLengthArray] Fixed a bug whereby a failed
append() would leave the container with an inconsistent size().
Pick-to: 6.2 5.15
Change-Id: Ief1e668d945149bd8ba96c8af1398baaa7876880
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qvarlengtharray.h | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 2a86a1dd7f..c412f96110 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -228,20 +228,19 @@ public: if (size() == capacity()) { // i.e. size() != 0 T copy(t); reallocate(size(), size() << 1); - const qsizetype idx = s++; - new (data() + idx) T(std::move(copy)); + new (end()) T(std::move(copy)); } else { - const qsizetype idx = s++; - new (data() + idx) T(t); + new (end()) T(t); } + ++s; } void append(T &&t) { if (size() == capacity()) reallocate(size(), size() << 1); - const qsizetype idx = s++; - new (data() + idx) T(std::move(t)); + new (end()) T(std::move(t)); + ++s; } void append(const T *buf, qsizetype size); |