From f276f9ec6bc187a7eebbc566fa3ce37311dbe871 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 12 Nov 2021 13:58:57 -0800 Subject: [PATCH] QCborValue: use assignContainer() in few more places Change-Id: I5e52dc5b093c43a3b678fffd16b6eb65ef37399d Reviewed-by: Edward Welbourne --- src/corelib/serialization/qcborvalue.cpp | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/corelib/serialization/qcborvalue.cpp b/src/corelib/serialization/qcborvalue.cpp index f7bbb8e695..37a2ff6473 100644 --- a/src/corelib/serialization/qcborvalue.cpp +++ b/src/corelib/serialization/qcborvalue.cpp @@ -772,7 +772,8 @@ static QCborContainerPrivate *assignContainer(QCborContainerPrivate *&d, QCborCo return d; if (d) d->deref(); - x->ref.ref(); + if (x) + x->ref.ref(); return d = x; } @@ -1911,13 +1912,8 @@ void QCborValue::dispose() */ QCborValue &QCborValue::operator=(const QCborValue &other) { - if (other.container) - other.container->ref.ref(); - if (container) - container->deref(); - n = other.n; - container = other.container; + assignContainer(container, other.container); t = other.t; return *this; } @@ -2276,16 +2272,11 @@ static QCborContainerPrivate *maybeGrow(QCborContainerPrivate *container, qsizet { auto replace = QCborContainerPrivate::grow(container, index); Q_ASSERT(replace); - if (replace != container) { - if (container) - container->deref(); - replace->ref.ref(); - } if (replace->elements.size() == index) replace->append(Undefined()); else Q_ASSERT(replace->elements.size() > index); - return replace; + return assignContainer(container, replace); } template inline QCborValueRef