summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization/qjsonobject.cpp
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2020-04-11 01:00:13 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2020-04-11 14:59:13 +0200
commit58a42898006f221807a08557f588a2d973a7ada2 (patch)
tree62d92617eae5df5aae666ea0902159498b285b24 /src/corelib/serialization/qjsonobject.cpp
parent033d01bd6e2aef740ad1408a04d3ca0ae3b9ba9b (diff)
parent1ec350e35fcea87c527b36cf429b595731059240 (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts: tests/auto/network/socket/platformsocketengine/platformsocketengine.pri Change-Id: I22daf269a8f28f80630b5f521b91637531156404
Diffstat (limited to 'src/corelib/serialization/qjsonobject.cpp')
-rw-r--r--src/corelib/serialization/qjsonobject.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/corelib/serialization/qjsonobject.cpp b/src/corelib/serialization/qjsonobject.cpp
index 1a85429c821..a03855d4a34 100644
--- a/src/corelib/serialization/qjsonobject.cpp
+++ b/src/corelib/serialization/qjsonobject.cpp
@@ -452,9 +452,11 @@ QJsonValueRef QJsonObject::atImpl(T key)
bool keyExists = false;
int index = indexOf(o, key, &keyExists);
if (!keyExists) {
+ detach2(o->elements.length() / 2 + 1);
o->insertAt(index, key);
o->insertAt(index + 1, QCborValue::fromJsonValue(QJsonValue()));
}
+ // detaching will happen if and when this QJsonValueRef is assigned to
return QJsonValueRef(this, index / 2);
}
@@ -1469,6 +1471,7 @@ QJsonValue QJsonObject::valueAt(int i) const
void QJsonObject::setValueAt(int i, const QJsonValue &val)
{
Q_ASSERT(o && i >= 0 && 2 * i + 1 < o->elements.length());
+ detach2();
if (val.isUndefined()) {
o->removeAt(2 * i + 1);
o->removeAt(2 * i);