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>
This commit is contained in:
Thiago Macieira 2019-03-07 22:16:21 -08:00
parent d5bb757987
commit 0181e0e527

View File

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