summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2021-08-18 17:27:04 +0200
committerIvan Solovev <ivan.solovev@qt.io>2021-08-19 16:42:32 +0200
commit5c4861d312110986b8ba31b88f71174553e71d69 (patch)
treea2557da0c5aa23aef99921159e0ee3589435dc90 /src
parent37b4c4d82f6bb59546721c4165a69849fd56b9d4 (diff)
QCborValue: add asserts to encoding method
This patch is inspired by CodeChecker, that is complaining about possible nullptr dereferencing. Currently it is a false-positive, because the codepath suggested by CodeChecker is impossible with current implementation. But having asserts can save some time in case of possible refactoring. Task-number: QTBUG-95727 Pick-to: 6.2 Change-Id: I242a23e8aaa249cce16b867c0884dfc3849977f5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/serialization/qcborvalue.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/corelib/serialization/qcborvalue.cpp b/src/corelib/serialization/qcborvalue.cpp
index d9358a6bf6..e6146c722e 100644
--- a/src/corelib/serialization/qcborvalue.cpp
+++ b/src/corelib/serialization/qcborvalue.cpp
@@ -1354,6 +1354,7 @@ static void encodeToCbor(QCborStreamWriter &writer, const QCborContainerPrivate
else
writer.endMap();
} else if (idx < 0) {
+ Q_ASSERT_X(d != nullptr, "QCborValue", "Unexpected null container");
if (d->elements.size() != 2) {
// invalid state!
qWarning("QCborValue: invalid tag state; are you encoding something that was improperly decoded?");
@@ -1364,6 +1365,7 @@ static void encodeToCbor(QCborStreamWriter &writer, const QCborContainerPrivate
writer.append(QCborTag(d->elements.at(0).value));
encodeToCbor(writer, d, 1, opt);
} else {
+ Q_ASSERT_X(d != nullptr, "QCborValue", "Unexpected null container");
// just one element
auto e = d->elements.at(idx);
const ByteData *b = d->byteData(idx);