diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2019-03-07 22:16:21 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2019-03-14 03:12:42 +0000 |
commit | 0181e0e527cfdceb6fcae5c3c1c3db5b9c340562 (patch) | |
tree | 14f14d7814c851e15c862c52ac038bfb8e650757 | |
parent | d5bb757987f5f759e37ebac402dbb07c2af01f69 (diff) |
Add a pair of functions to convert to and from Q/CborError
We've so far made our public API match the TinyCBOR error codes, so the
conversion is trivial. Having the two functions allows us to change
that, if it becomes necessary.
It also effectively concentrates the Coverity warning about mixed enums
in a single pair of functions.
>>> CID 190307: Incorrect expression (MIXED_ENUMS)
>>> Mixing enum types "CborError" and "QCborError::Code" for "err".
Change-Id: Ifbadc62ac2d04a9a8952fffd1589e739c7a5b745
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r-- | src/corelib/serialization/qcborstream.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/corelib/serialization/qcborstream.cpp b/src/corelib/serialization/qcborstream.cpp index 264856b4bf..7ccc0ff3a7 100644 --- a/src/corelib/serialization/qcborstream.cpp +++ b/src/corelib/serialization/qcborstream.cpp @@ -413,6 +413,24 @@ QDebug operator<<(QDebug dbg, QCborKnownTags tag) support (internal limitation, but the error is not recoverable). */ +// Convert from CborError to QCborError. +// +// Centralized in a function in case we need to make more adjustments in the +// future. +static QCborError fromCborError(CborError err) +{ + return { QCborError::Code(int(err)) }; +} + +// Convert to CborError from QCborError. +// +// Centralized in a function in case we need to make more adjustments in the +// future. +static CborError toCborError(QCborError c) +{ + return CborError(int(c.c)); +} + /*! \variable QCborError::c \internal @@ -483,8 +501,8 @@ QString QCborError::toString() const return QStringLiteral("Internal limitation: unsupported type"); } - // get the error from TinyCBOR - CborError err = CborError(int(c)); + // get the error string from TinyCBOR + CborError err = toCborError(*this); return QString::fromLatin1(cbor_error_string(err)); } @@ -1823,8 +1841,7 @@ public: if (err != CborErrorUnexpectedEOF) corrupt = true; - // our error codes are the same (for now) - lastError = { QCborError::Code(err) }; + lastError = fromCborError(err); } void updateBufferAfterString(qsizetype offset, qsizetype size) |