summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2018-10-27 19:43:09 -0700
committerThiago Macieira <thiago.macieira@intel.com>2018-11-08 15:19:45 +0000
commite7998dc187cf8f1218711ac963c441afbea1577c (patch)
treef367243b5781f09d688d71b9d15c6fcf5a48ecaa
parentc0b1230108090cf914ccc5329b1213063ed21bdd (diff)
QCborStreamReader: make sure setDevice() clears the last error
The unit tests weren't running into this problem because the every setDevice() was preceded by the object being initialized with the exact same data, so there was never a previous error state. I've only changed a couple of tests, left the other setDevice() unchanged so we test both behaviors. Fixes: QTBUG-71426 Change-Id: I1bd327aeaf73421a8ec5fffd1561a590e3933376 Reviewed-by: Nils Jeisecke <nils.jeisecke@saltation.com> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
-rw-r--r--src/corelib/serialization/qcborstream.cpp2
-rw-r--r--tests/auto/corelib/serialization/qcborstreamreader/tst_qcborstreamreader.cpp4
2 files changed, 4 insertions, 2 deletions
diff --git a/src/corelib/serialization/qcborstream.cpp b/src/corelib/serialization/qcborstream.cpp
index 22286188b8..fc5610e341 100644
--- a/src/corelib/serialization/qcborstream.cpp
+++ b/src/corelib/serialization/qcborstream.cpp
@@ -1779,6 +1779,8 @@ public:
preread();
if (CborError err = cbor_parser_init_reader(nullptr, &parser, &currentElement, this))
handleError(err);
+ else
+ lastError = { QCborError::NoError };
}
char *bufferPtr()
diff --git a/tests/auto/corelib/serialization/qcborstreamreader/tst_qcborstreamreader.cpp b/tests/auto/corelib/serialization/qcborstreamreader/tst_qcborstreamreader.cpp
index 24d9c7409e..3dd4b5114c 100644
--- a/tests/auto/corelib/serialization/qcborstreamreader/tst_qcborstreamreader.cpp
+++ b/tests/auto/corelib/serialization/qcborstreamreader/tst_qcborstreamreader.cpp
@@ -269,7 +269,7 @@ void tst_QCborStreamReader::integers()
quint64 absolute = (isNegative ? expectedRaw + 1 : expectedRaw);
QBuffer buffer(&data);
- QCborStreamReader reader(data);
+ QCborStreamReader reader(useDevice ? QByteArray() : data);
if (useDevice) {
buffer.open(QIODevice::ReadOnly);
reader.setDevice(&buffer);
@@ -605,7 +605,7 @@ void tst_QCborStreamReader::fixed()
removeIndicators(expected);
QBuffer buffer(&data);
- QCborStreamReader reader(data);
+ QCborStreamReader reader(useDevice ? QByteArray() : data);
if (useDevice) {
buffer.open(QIODevice::ReadOnly);
reader.setDevice(&buffer);