Add EndCheck(); change QCBORDecode_Tell() behavior (#231)
QCBORDecode_Tell() returns the offset when at the end of the input rather than UINT32_MAX. This is a non-compatible change, but QCBORDecode_Tell() was very recently introduced and is not present in any official releases.
QCBORDecode_EndCheck() is added to check to see if the cursor is at the end of the input.
Addresses #230
* Add EndCheck(); change Tell() behavior
* Minor corrections
* Minor doc update
---------
Co-authored-by: Laurence Lundblade <lgl@securitytheory.com>
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index 3ed4d0f..9bd518e 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -3219,23 +3219,24 @@
/*
* Public function, see header qcbor/qcbor_decode.h file
*/
-uint32_t
-QCBORDecode_Tell(QCBORDecodeContext *pMe)
+QCBORError
+QCBORDecode_EndCheck(QCBORDecodeContext *pMe)
{
- size_t uCursorOffset;
+ size_t uCursorOffset;
+ QCBORError uErr;
- if(pMe->uLastError != QCBOR_SUCCESS) {
- return UINT32_MAX;
+ uErr = QCBORDecode_GetError(pMe);
+ if(uErr != QCBOR_SUCCESS) {
+ return uErr;
}
uCursorOffset = UsefulInputBuf_Tell(&(pMe->InBuf));
if(uCursorOffset == UsefulInputBuf_GetBufferLength(&(pMe->InBuf))) {
- return UINT32_MAX;
- } else {
- /* Cast is safe because decoder input size is restricted. */
- return (uint32_t)uCursorOffset;
+ return QCBOR_ERR_NO_MORE_ITEMS;
}
+
+ return QCBOR_SUCCESS;
}