diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2018-09-20 13:36:05 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2018-10-08 14:11:08 +0000 |
commit | ff7f09d18708119bebb94202d3a3dcb26149ee5a (patch) | |
tree | aa15d57cd1fdb9eed9776db38360ab0b4e59cb64 /src/corelib/serialization/qcborvalue.cpp | |
parent | 7f079bf9d0f534fcec747f965565d99845df7aba (diff) |
Change QCborArray to pad with invalid on inserting past end
Likewise have mutating operator[] insert an invalid entry at its
target index, if beyond the end of the array. This makes it possible
to fill an array from high index to low, for example.
Change-Id: If71699c20e2623142214ce2c11c4d6e4a120c989
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/serialization/qcborvalue.cpp')
-rw-r--r-- | src/corelib/serialization/qcborvalue.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/corelib/serialization/qcborvalue.cpp b/src/corelib/serialization/qcborvalue.cpp index 077a4754dc..81ea1ed3b2 100644 --- a/src/corelib/serialization/qcborvalue.cpp +++ b/src/corelib/serialization/qcborvalue.cpp @@ -859,6 +859,23 @@ QCborContainerPrivate *QCborContainerPrivate::detach(QCborContainerPrivate *d, q return d; } +/*! + Prepare for an insertion at position \a index + + Detaches and ensures there are at least index entries in the array, padding + with Undefined as needed. +*/ +QCborContainerPrivate *QCborContainerPrivate::grow(QCborContainerPrivate *d, qsizetype index) +{ + Q_ASSERT(index >= 0); + d = detach(d, index + 1); + Q_ASSERT(d); + int j = d->elements.size(); + while (j < index) + d->append(Undefined()); + return d; +} + // Copies or moves \a value into element at position \a e. If \a disp is // CopyContainer, then this function increases the reference count of the // container, but otherwise leaves it unmodified. If \a disp is MoveContainer, |