bounded empty maps and arrays might actually be working
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index 6f60ef6..e5a4cab 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -117,7 +117,7 @@
 }
 
 
-static inline size_t
+static inline uint32_t
 DecodeNesting_GetMapOrArrayStart(const QCBORDecodeNesting *pNesting)
 {
    return pNesting->pCurrentBounded->u.ma.uStartOffset;
@@ -1344,6 +1344,7 @@
             uReturn = QCBOR_ERR_BAD_BREAK;
             goto Done;
          }
+         
          /* It was a break in an indefinite length map / array */
       }
 
@@ -2382,6 +2383,10 @@
 {
    QCBORError uReturn;
 
+    if(pMe->uLastError != QCBOR_SUCCESS) {
+        return pMe->uLastError;
+    }
+
    QCBORDecodeNesting SaveNesting = pMe->nesting; // TODO: refactor?
 
    uint64_t uFoundItemBitMap = 0;
@@ -2398,10 +2403,11 @@
       // It is an empty bounded array or map
       if(pItemArray->uLabelType == QCBOR_TYPE_NONE) {
          // Just trying to find the end of the map or array
+         pMe->uMapEndOffsetCache = DecodeNesting_GetMapOrArrayStart(&(pMe->nesting));
          uReturn = QCBOR_SUCCESS;
-         pMe->uMapEndOffsetCache = (uint32_t)DecodeNesting_GetMapOrArrayStart(&(pMe->nesting));
       } else {
-         // Nothing is ever found in an empty array or map
+         // Nothing is ever found in an empty array or map. All items
+         // are marked as not found below.
          uReturn = QCBOR_SUCCESS;
       }
       goto Done;
@@ -2825,6 +2831,11 @@
 
    const bool bIsEmpty = Item.uNestingLevel == Item.uNextNestLevel;
    if(bIsEmpty) {
+      if(DecodeNesting_IsCurrentDefiniteLength(&(pMe->nesting))) {
+         // Undo decrement done by QCBORDecode_GetNext() so the the
+         // the decrement when exiting the map / array works correctly
+         pMe->nesting.pCurrent->u.ma.uCountCursor++;
+      }
       // Special case to increment nesting level for zero-length maps and arrays entered in bounded mode.
       DecodeNesting_Descend(&(pMe->nesting), uType);
    }
@@ -2836,13 +2847,13 @@
 
    pMe->uLastError = (uint8_t)uErr;
 
-   DecodeNesting_Print(&(pMe->nesting), &(pMe->InBuf),  "EnterMapModeDone");
+   DecodeNesting_Print(&(pMe->nesting), &(pMe->InBuf), "EnterMapModeDone");
 }
 
 
 /*
- This is for exiting a level that is a bounded map, array or bstr
- wrapped CBOR. It is the work common to these.
+ This is the common work for exiting a level that is a bounded map, array or bstr
+ wrapped CBOR.
 
  One chunk of work is to set up the pre-order traversal so it is at
  the item just after the bounded map, array or bstr that is being
@@ -3165,12 +3176,12 @@
       return;
    }
 
-   QCBORError nError;
+   QCBORError uError;
    QCBORItem  Item;
 
-   nError = QCBORDecode_GetNext(pMe, &Item);
-   if(nError != QCBOR_SUCCESS) {
-      pMe->uLastError = (uint8_t)nError;
+   uError = QCBORDecode_GetNext(pMe, &Item);
+   if(uError != QCBOR_SUCCESS) {
+      pMe->uLastError = (uint8_t)uError;
       return;
    }
 
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 3d40ab9..0fe95d2 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -4045,6 +4045,8 @@
 
 static const uint8_t spEmptyInDefinteLengthMap[] = {0xbf, 0xff};
 
+static const uint8_t spArrayOfEmpty[] = {0x84, 0x40, 0xa0, 0x80, 0x00};
+
 int32_t EnterMapTest()
 {
    QCBORItem Item1;
@@ -4169,6 +4171,21 @@
       return 2013;
    }
 
+
+   QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spArrayOfEmpty), 0);
+   QCBORDecode_EnterArray(&DCtx);
+   QCBORDecode_GetBytes(&DCtx, &String);
+   QCBORDecode_EnterMap(&DCtx);
+   QCBORDecode_ExitMap(&DCtx);
+   QCBORDecode_EnterArray(&DCtx);
+   QCBORDecode_ExitArray(&DCtx);
+   QCBORDecode_GetInt64(&DCtx, &nDecodedInt2);
+   QCBORDecode_ExitArray(&DCtx);
+   uErr = QCBORDecode_Finish(&DCtx);
+   if(uErr != QCBOR_SUCCESS){
+      return 2014;
+   }
+
    return 0;
 }