bug fix in indefinite length array decoding; all but one tests are passing and this test kind of has a problem
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index 7189c20..410af46 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -150,6 +150,9 @@
// Pop up nesting levels if the counts at the levels are zero
while(DecodeNesting_IsNested(pNesting) && 0 == pNesting->pCurrent->uCount) {
pNesting->pCurrent--;
+ if(!DecodeNesting_IsIndefiniteLength(pNesting)) {
+ pNesting->pCurrent->uCount--;
+ }
}
}
@@ -532,6 +535,25 @@
pDecodedItem->val.epochDate.nSeconds = Item.val.uint64;
break;
+ case QCBOR_TYPE_FLOAT:
+ // TODO: can we save code by widening a float to a double here? Then drop into double-handling code
+ if(Item.val.fnum > INT64_MAX) {
+ nReturn = QCBOR_ERR_DATE_OVERFLOW;
+ goto Done;
+ }
+ pDecodedItem->val.epochDate.nSeconds = Item.val.fnum;
+ pDecodedItem->val.epochDate.fSecondsFraction = Item.val.fnum - pDecodedItem->val.epochDate.nSeconds;
+ break;
+
+ case QCBOR_TYPE_DOUBLE:
+ if(Item.val.dfnum > INT64_MAX) {
+ nReturn = QCBOR_ERR_DATE_OVERFLOW;
+ goto Done;
+ }
+ pDecodedItem->val.epochDate.nSeconds = Item.val.dfnum;
+ pDecodedItem->val.epochDate.fSecondsFraction = Item.val.dfnum - pDecodedItem->val.epochDate.nSeconds;
+ break;
+
default:
nReturn = QCBOR_ERR_BAD_OPT_TAG;
}
@@ -869,7 +891,7 @@
/* Loops processing breaks until a non-break is encountered
or an error is encountered
*/
-static int LoopOverBreaks(QCBORDecodeContext *me, QCBORItem *pDecodedItem)
+static int GetNext_GetNonBreak(QCBORDecodeContext *me, QCBORItem *pDecodedItem)
{
int nReturn = QCBOR_SUCCESS;
@@ -912,7 +934,7 @@
int nReturn;
// Loop getting items until one that is not a break is fetched
- nReturn = LoopOverBreaks(me, pDecodedItem);
+ nReturn = GetNext_GetNonBreak(me, pDecodedItem);
if(nReturn) {
goto Done;
}
@@ -923,13 +945,19 @@
// decrementing and decsending
pDecodedItem->uNestingLevel = DecodeNesting_GetLevel(&(me->nesting));
- // Always decrement the count at the current level no matter what type
- // except for breaks as breaks are always processed above
- DecodeNesting_DecrementCount(&(me->nesting));
-
- // If the new item is array or map, the nesting level descends
if(IsMapOrArray(pDecodedItem->uDataType)) {
+ // If the new item is array or map, the nesting level descends
nReturn = DecodeNesting_Descend(&(me->nesting), pDecodedItem);
+ // Maps and arrays do count in as items in the map/array that encloses
+ // them so a decrement needs to be done for them too, but that is done
+ // only when all the items in them have been processed, not when they
+ // are opened.
+ } else {
+ // Decrement the count of items in the enclosing map/array
+ // If the count in the enclosing map/array goes to zero, that
+ // triggers a decrement for in the map/array above that and
+ // and ascend in mnesting level.
+ DecodeNesting_DecrementCount(&(me->nesting));
}
Done:
@@ -949,7 +977,7 @@
// the last item in them is consumed; they are not handled here.
if(DecodeNesting_IsNested(&(me->nesting))) {
QCBORItem Item;
- nReturn = LoopOverBreaks(me, &Item);
+ nReturn = GetNext_GetNonBreak(me, &Item);
if(nReturn) {
goto Done;
}
@@ -1043,8 +1071,8 @@
if(pMem) {
// Realloc case
// TODO: review this pointer math
- if((uint8_t *)pMem + uNewSize <= me->pEnd && (uint8_t *)pMem > me->pStart) {
- me->pFree = pMem + uNewSize;
+ if((uint8_t *)pMem + uNewSize <= me->pEnd) {//} && (uint8_t *)pMem > me->pStart) {
+ me->pFree = (uint8_t *)pMem + uNewSize;
pReturn = pMem;
}
} else {