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>
This commit is contained in:
Ivan Solovev 2021-08-18 17:27:04 +02:00
parent 37b4c4d82f
commit 5c4861d312

View File

@ -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);