fixed cbor sequence bug
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index de5d77b..13be1f7 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -131,19 +131,13 @@
}
}
-// Determine if at the end of a map or array, taking into
-// account map mode. If this returns true, it is OK
-// to get another item.
+// Determine if at the end of a map or array while in map mode
inline static bool
DecodeNesting_AtEnd(const QCBORDecodeNesting *pNesting)
{
- if(DecodeNesting_IsAtTop(pNesting)){
- // Always at end if at the top level of nesting
- return true;
- }
-
if(pNesting->pCurrent->uMapMode) {
if(pNesting->pCurrent->uCount == 0) {
+ // TODO: won't work for indefinite length
// In map mode and consumed all items, so it is the end
return true;
} else {
@@ -151,7 +145,7 @@
return false;
}
} else {
- // Not in map mode, and not at top level so it NOT the end.
+ // Not in map mode. The end is determined in other ways.
return false;
}
}
@@ -1173,14 +1167,24 @@
QCBORError nReturn;
- // Check if there are an TODO: incomplete comment
+ /* For a pre-order traversal a non-error end occurs when there
+ are no more bytes to consume and the nesting level is at the top.
+ If it's not at the top, then the CBOR is not well formed. This error
+ is caught elsewhere.
+
+ This handles the end of CBOR sequences as well as non-sequences. */
if(UsefulInputBuf_BytesUnconsumed(&(me->InBuf)) == 0 && DecodeNesting_IsAtTop(&(me->nesting))) {
nReturn = QCBOR_ERR_NO_MORE_ITEMS;
goto Done;
}
-
+
+ /* It is also and end of the input when in map mode and the cursor
+ is at the end of the map */
+
+
// This is to handle map and array mode
- if(UsefulInputBuf_Tell(&(me->InBuf)) != 0 && DecodeNesting_AtEnd(&(me->nesting))) {
+ if(DecodeNesting_AtEnd(&(me->nesting))) {
+// if(UsefulInputBuf_Tell(&(me->InBuf)) != 0 && DecodeNesting_AtEnd(&(me->nesting))) {
nReturn = QCBOR_ERR_NO_MORE_ITEMS;
goto Done;
}