diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2020-04-08 11:47:33 -0300 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2020-04-09 09:41:40 -0300 |
commit | 57a57fda78bab652e3fb79677bd828b0f0b49962 (patch) | |
tree | 74cb144fe0f731eca43754f9076c07128e4d878d /src/corelib | |
parent | ddc7b3c1565b5f7100df4d13e5501f76db2730ee (diff) |
QCborMap: fix assigning elements from the map to itself
Similar to the QJsonObject issue of the previous commit (found with the
same tests, but not the same root cause). One fix was that copying of
byte data from the QByteArray to itself won't work if the array
reallocates. The second was that
assign(*that, other.concrete());
fails to set other.d to null after moving. By calling the operator=, we
get the proper sequence of events.
[ChangeLog][QtCore][QCborMap] Fixed some issues relating to assigning
elements from a map to itself.
Note: QCborMap is not affected by the design flaw discovered in
QJsonObject because it always appends elements (it's unsorted), so
existing QCborValueRef references still refer to the same value.
Task-number: QTBUG-83366
Change-Id: Ibdc95e9af7bd456a94ecfffd1603df846f46094d
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/serialization/qcborvalue.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/corelib/serialization/qcborvalue.cpp b/src/corelib/serialization/qcborvalue.cpp index 63ee5f3158..ebb3665e0c 100644 --- a/src/corelib/serialization/qcborvalue.cpp +++ b/src/corelib/serialization/qcborvalue.cpp @@ -994,8 +994,12 @@ void QCborContainerPrivate::replaceAt_complex(Element &e, const QCborValue &valu e = value.container->elements.at(value.n); // Copy string data, if any - if (const ByteData *b = value.container->byteData(value.n)) - e.value = addByteData(b->byte(), b->len); + if (const ByteData *b = value.container->byteData(value.n)) { + if (this == value.container) + e.value = addByteData(b->toByteArray(), b->len); + else + e.value = addByteData(b->byte(), b->len); + } if (disp == MoveContainer) value.container->deref(); @@ -2649,7 +2653,7 @@ void QCborValueRef::assign(QCborValueRef that, QCborValue &&other) void QCborValueRef::assign(QCborValueRef that, const QCborValueRef other) { // ### optimize? - assign(that, other.concrete()); + that = other.concrete(); } QCborValue QCborValueRef::concrete(QCborValueRef self) noexcept |