Rearrange error codes to group not-well-formed together; entering empty maps and arrays kind of working
diff --git a/README.md b/README.md
index 113c542..b5417a0 100644
--- a/README.md
+++ b/README.md
@@ -137,7 +137,7 @@
 
 In line with all the new Get functions for non-aggregate types
 there are new Enter functions for aggregate types. When
-an array or map is expected, Enter is called to decsend
+an array or map is expected, Enter is called to descend
 into them. When a map is Entered it can be searched
 by label. Duplicate detection of map items is performed.
 
diff --git a/inc/qcbor/qcbor_common.h b/inc/qcbor/qcbor_common.h
index 37b910b..7c225e9 100644
--- a/inc/qcbor/qcbor_common.h
+++ b/inc/qcbor/qcbor_common.h
@@ -215,32 +215,28 @@
    /** The encode or decode completely correctly. */
    QCBOR_SUCCESS = 0,
 
-   /** The buffer provided for the encoded output when doing encoding
-       was too small and the encoded output will not fit. Also, when
-       the buffer given to QCBORDecode_SetMemPool() is too small. */
-   QCBOR_ERR_BUFFER_TOO_SMALL = 1,
+   /** During decoding, the CBOR is not valid, primarily a simple type
+       is encoded in a prohibited way. */
+   QCBOR_ERR_BAD_TYPE_7 = 1,
 
-   /** During encoding or decoding, the array or map nesting was
-       deeper than this implementation can handle. Note that in the
-       interest of code size and memory use, this implementation has a
-       hard limit on array nesting. The limit is defined as the
-       constant @ref QCBOR_MAX_ARRAY_NESTING. */
-   QCBOR_ERR_ARRAY_NESTING_TOO_DEEP = 2,
+#define QCBOR_ERR_FIRST_NOT_WELL_FORMED QCBOR_ERR_BAD_TYPE_7
 
-   /** During decoding or encoding, the array or map had too many
-       items in it.  This limit @ref QCBOR_MAX_ITEMS_IN_ARRAY,
-       typically 65,535. */
-   QCBOR_ERR_ARRAY_TOO_LONG = 3,
+   /** Returned by QCBORDecode_Finish() if all the inputs bytes have
+       not been consumed. */
+   QCBOR_ERR_EXTRA_BYTES = 2,
 
-   /** During encoding, more arrays or maps were closed than
-       opened. This is a coding error on the part of the caller of the
-       encoder. */
-   QCBOR_ERR_TOO_MANY_CLOSES = 4,
+   /** One of the chunks in an indefinite-length string is not of the
+       type of the start of the string. */
+   QCBOR_ERR_INDEFINITE_STRING_CHUNK = 3,
+
+   /** During decoding, a break occurred outside an indefinite-length
+       item. */
+   QCBOR_ERR_BAD_BREAK = 4,
 
    /** During decoding, some CBOR construct was encountered that this
        decoder doesn't support, primarily this is the reserved
-       additional info values, 28 through 30. During encoding,
-       an attempt to create simple value between 24 and 31. */
+       additional info values, 28 through 30. During encoding, an
+       attempt to create simple value between 24 and 31. */
    QCBOR_ERR_UNSUPPORTED = 5,
 
    /** During decoding, hit the end of the given data to decode. For
@@ -251,38 +247,42 @@
      */
    QCBOR_ERR_HIT_END = 6,
 
-   /** During encoding, the length of the encoded CBOR exceeded @c
-       UINT32_MAX. */
-   QCBOR_ERR_BUFFER_TOO_LARGE = 7,
+   /** During encoding or decoding, the number of array or map opens
+       was not matched by the number of closes. */
+   QCBOR_ERR_ARRAY_OR_MAP_STILL_OPEN = 7,
 
-   /** During decoding, an integer smaller than INT64_MIN was received
-       (CBOR can represent integers smaller than INT64_MIN, but C
-       cannot). */
-   QCBOR_ERR_INT_OVERFLOW = 8,
+   /** An integer type is encoded with a bad length (an indefinite length) */
+   QCBOR_ERR_BAD_INT = 8,
+
+#define QCBOR_ERR_LAST_NOT_WELL_FORMED QCBOR_ERR_BAD_INT
 
    /** During decoding, the label for a map entry is bad. What causes
        this error depends on the decoding mode. */
    QCBOR_ERR_MAP_LABEL_TYPE = 9,
 
-   /** During encoding or decoding, the number of array or map opens
-       was not matched by the number of closes. */
-   QCBOR_ERR_ARRAY_OR_MAP_STILL_OPEN = 10,
+   /** During encoding, the length of the encoded CBOR exceeded @c
+       UINT32_MAX. */
+   QCBOR_ERR_BUFFER_TOO_LARGE = 10,
 
    /** During decoding, a date greater than +- 292 billion years from
        Jan 1 1970 encountered during parsing. */
    QCBOR_ERR_DATE_OVERFLOW = 11,
 
-   /** During decoding, the CBOR is not valid, primarily a simple type
-      is encoded in a prohibited way. */
-   QCBOR_ERR_BAD_TYPE_7 = 12,
+   /** The buffer provided for the encoded output when doing encoding
+       was too small and the encoded output will not fit. Also, when
+       the buffer given to QCBORDecode_SetMemPool() is too small. */
+   QCBOR_ERR_BUFFER_TOO_SMALL = 12,
 
    /** Optional tagging that doesn't make sense (an integer is tagged
        as a date string) or can't be handled. */
    QCBOR_ERR_BAD_OPT_TAG = 13,
 
-   /** Returned by QCBORDecode_Finish() if all the inputs bytes have
-       not been consumed. */
-   QCBOR_ERR_EXTRA_BYTES = 14,
+   /** During encoding or decoding, the array or map nesting was
+       deeper than this implementation can handle. Note that in the
+       interest of code size and memory use, this implementation has a
+       hard limit on array nesting. The limit is defined as the
+       constant @ref QCBOR_MAX_ARRAY_NESTING. */
+   QCBOR_ERR_ARRAY_NESTING_TOO_DEEP = 14,
 
    /** During encoding, @c QCBOREncode_CloseXxx() called with a
        different type than is currently open. Also during decoding,
@@ -295,78 +295,87 @@
        QCBORDecode_SetUpAllocator(). */
    QCBOR_ERR_NO_STRING_ALLOCATOR = 16,
 
-   /** One of the chunks in an indefinite-length string is not of the
-       type of the start of the string. */
-   QCBOR_ERR_INDEFINITE_STRING_CHUNK = 17,
+    /** During decoding or encoding, the array or map had too many
+        items in it.  This limit @ref QCBOR_MAX_ITEMS_IN_ARRAY,
+        typically 65,535. */
+    QCBOR_ERR_ARRAY_TOO_LONG = 17,
 
    /** Error allocating space for a string, usually for an
        indefinite-length string. */
    QCBOR_ERR_STRING_ALLOCATE = 18,
 
-   /** During decoding, a break occurred outside an indefinite-length
-       item. */
-   QCBOR_ERR_BAD_BREAK = 19,
+    /** During encoding, more arrays or maps were closed than
+        opened. This is a coding error on the part of the caller of
+        the encoder. */
+    QCBOR_ERR_TOO_MANY_CLOSES = 19,
 
-   /** More than @ref QCBOR_MAX_TAGS_PER_ITEM tags encounterd for a CBOR ITEM.
-      @ref QCBOR_MAX_TAGS_PER_ITEM is a limit of this implementation.
-      During decoding, too many tags in the caller-configured tag
-       list, or not enough space in @ref QCBORTagListOut. */
+   /** More than @ref QCBOR_MAX_TAGS_PER_ITEM tags encounterd for a
+       CBOR ITEM.  @ref QCBOR_MAX_TAGS_PER_ITEM is a limit of this
+       implementation.  During decoding, too many tags in the
+       caller-configured tag list, or not enough space in @ref
+       QCBORTagListOut. */
    QCBOR_ERR_TOO_MANY_TAGS = 20,
 
-   /** An integer type is encoded with a bad length (an indefinite length) */
-   QCBOR_ERR_BAD_INT = 21,
+    /** During decoding, an integer smaller than INT64_MIN was
+        received (CBOR can represent integers smaller than INT64_MIN,
+        but C cannot). */
+   QCBOR_ERR_INT_OVERFLOW = 21,
 
    /** All well-formed data items have been consumed and there are no
-       more. If parsing a CBOR stream this indicates the non-error
-       end of the stream. If parsing a CBOR stream / sequence, this
-       probably indicates that some data items expected are not present.
-       See also @ref QCBOR_ERR_HIT_END. */
+       more. If parsing a CBOR stream this indicates the non-error end
+       of the stream. If parsing a CBOR stream / sequence, this
+       probably indicates that some data items expected are not
+       present.  See also @ref QCBOR_ERR_HIT_END. */
    QCBOR_ERR_NO_MORE_ITEMS = 22,
 
    /** Something is wrong with a decimal fraction or bigfloat such as
-    it not consisting of an array with two integers */
+       it not consisting of an array with two integers */
    QCBOR_ERR_BAD_EXP_AND_MANTISSA = 23,
 
-   /** When decoding, a string's size is greater than size_t. In all but some
-    very strange situations this is because of corrupt input CBOR and
-    should be treated as such. The strange situation is a CPU with a very
-    small size_t (e.g., a 16-bit CPU) and a large string (e.g., > 65KB).
+   /** When decoding, a string's size is greater than size_t. In all
+       but some very strange situations this is because of corrupt
+       input CBOR and should be treated as such. The strange situation
+       is a CPU with a very small size_t (e.g., a 16-bit CPU) and a
+       large string (e.g., > 65KB).
     */
-    QCBOR_ERR_STRING_TOO_LONG = 24,
+   QCBOR_ERR_STRING_TOO_LONG = 24,
     
-    /** When decodeing for a specific type, the type was not was expected.
-     See also @ref QCBOR_ERR_CONVERSION_NOT_REQUESTED which in many cases
-     is effectively the same error */
-    QCBOR_ERR_UNEXPECTED_TYPE = 25,
+   /** When decodeing for a specific type, the type was not was
+       expected.  See also @ref QCBOR_ERR_CONVERSION_NOT_REQUESTED
+       which in many cases is effectively the same error */
+   QCBOR_ERR_UNEXPECTED_TYPE = 25,
     
-    /** Duplicate label in map detected */
-    QCBOR_ERR_DUPLICATE_LABEL = 26,
+   /** Duplicate label in map detected */
+   QCBOR_ERR_DUPLICATE_LABEL = 26,
     
-    /** Item with requested label is not found */
-    QCBOR_ERR_NOT_FOUND = 27,
+   /** Item with requested label is not found */
+   QCBOR_ERR_NOT_FOUND = 27,
 
-    /** Number conversion failed because of sign. For example a negative
-     int64_t can't be converted to a uint64_t */
-    QCBOR_ERR_NUMBER_SIGN_CONVERSION = 28,
+   /** Number conversion failed because of sign. For example a
+       negative int64_t can't be converted to a uint64_t */
+   QCBOR_ERR_NUMBER_SIGN_CONVERSION = 28,
 
-    /** A conversion is possible, but the option for it was not set. For
-     example conversion from a float to an int64_t without the XXX option. TODO: */
-    QCBOR_ERR_CONVERSION_NOT_REQUESTED = 29,
+   /** A conversion is possible, but the option for it was not
+       set. For example conversion from a float to an int64_t without
+       the XXX option. TODO: */
+   QCBOR_ERR_CONVERSION_NOT_REQUESTED = 29,
 
-    /** When converting a decoded number, the value is too large or to small
-     for the conversion target */
-    QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW = 30,
+   /** When converting a decoded number, the value is too large or to
+       small for the conversion target */
+   QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW = 30,
     
-    /** Trying to get an item by label when a map has not been entered. */
-    QCBOR_ERR_NOT_ENTERED = 31,
+   /** Trying to get an item by label when a map has not been entered. */
+   QCBOR_ERR_NOT_ENTERED = 31,
 
-    /** A callback indicates processing should not continue for some non-CBOR reason */
-    QCBOR_ERR_CALLBACK_FAIL = 32,
+   /** A callback indicates processing should not continue for some
+       non-CBOR reason */
+   QCBOR_ERR_CALLBACK_FAIL = 32,
 
-    /** Trying to get something by label when not entered into a map.  */
-    QCBOR_ERR_NOT_A_MAP = 33
+   /** Trying to get something by label when not entered into a
+       map.  */
+   QCBOR_ERR_NOT_A_MAP = 33
 
-    /* This is stored in uint8_t; never add values > 255 */
+   /* This is stored in uint8_t; never add values > 255 */
 } QCBORError;
 
 
diff --git a/inc/qcbor/qcbor_decode.h b/inc/qcbor/qcbor_decode.h
index 9b468cc..1a33bce 100644
--- a/inc/qcbor/qcbor_decode.h
+++ b/inc/qcbor/qcbor_decode.h
@@ -1058,6 +1058,14 @@
 static QCBORError QCBORDecode_GetAndResetError(QCBORDecodeContext *pCtx);
 
 
+/**
+ @brief Whether an error indicates non-well-formed CBOR.
+
+ @param[in] uErr    The decoder context.
+ @return @c true if the error code indicates non-well-formed CBOR.
+ */
+static bool QCBORDecode_IsNotWellFormed(QCBORError uErr);
+
 
 /*
  TODO: get rid of this
@@ -1099,9 +1107,6 @@
 
  See also QCBORDecode_GetInt64Convert() and QCBORDecode_GetInt64ConvertAll().
 
-
- A) A separate API for positive than negative
- B)
  */
 static void QCBORDecode_GetInt64(QCBORDecodeContext *pCtx, int64_t *pnValue);
 
@@ -1940,7 +1945,7 @@
  This will return maps and arrays that are in the map, but
  provides no way to descend into and decode them. Use
  QCBORDecode_EnterMapinMapN(), QCBORDecode_EnterArrayInMapN()
- and such to decsend into and process maps and arrays.
+ and such to descend into and process maps and arrays.
  */
 QCBORError QCBORDecode_GetItemsInMap(QCBORDecodeContext *pCtx, QCBORItem *pItemList);
 
@@ -2197,6 +2202,17 @@
     return uReturn;
 }
 
+// TODO: test this
+static inline bool QCBORDecode_IsNotWellFormed(QCBORError uErr)
+{
+   if(uErr >= QCBOR_ERR_FIRST_NOT_WELL_FORMED && uErr <= QCBOR_ERR_LAST_NOT_WELL_FORMED) {
+      return true;
+   } else {
+      return false;
+   }
+}
+
+
 
 // Semi-private
 void QCBORDecode_EnterBoundedMapOrArray(QCBORDecodeContext *pMe, uint8_t uType);
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index 511de13..0c3105c 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -279,7 +279,7 @@
 
 
 static QCBORError
-DecodeNesting_Decsend(QCBORDecodeNesting *pNesting, uint8_t uType)
+DecodeNesting_Descend(QCBORDecodeNesting *pNesting, uint8_t uType)
 {
    // Error out if nesting is too deep
    if(pNesting->pCurrent >= &(pNesting->pLevels[QCBOR_MAX_ARRAY_NESTING])) {
@@ -336,12 +336,12 @@
       goto Done;
    }
 
-   uError = DecodeNesting_Decsend(pNesting, uQCBORType);
+   uError = DecodeNesting_Descend(pNesting, uQCBORType);
    if(uError != QCBOR_SUCCESS) {
       goto Done;
    }
 
-   // Fill in the new map/array level. Check above makes cast OK.
+   // Fill in the new map/array level. Check above makes casts OK.
    pNesting->pCurrent->u.ma.uCountCursor  = (uint16_t)uCount;
    pNesting->pCurrent->u.ma.uCountTotal   = (uint16_t)uCount;
 
@@ -384,7 +384,7 @@
 {
    QCBORError uError = QCBOR_SUCCESS;
 
-   uError = DecodeNesting_Decsend(pNesting, QCBOR_TYPE_BYTE_STRING);
+   uError = DecodeNesting_Descend(pNesting, QCBOR_TYPE_BYTE_STRING);
    if(uError != QCBOR_SUCCESS) {
       goto Done;
    }
@@ -1356,7 +1356,7 @@
 
 
 /*
- This the travesal going descending into and asecnding out of maps,
+ This handles the traversal descending into and asecnding out of maps,
  arrays and bstr-wrapped CBOR. It figures out the ends of definite and
  indefinte length maps and arrays by looking at the item count or
  finding CBOR breaks.  It detects the ends of the top-level sequence
@@ -1376,17 +1376,8 @@
     was set to that of the bstr-wrapped CBOR. When the bstr-wrapped
     CBOR is exited, the length is set back to the top-level's length
     or to the next highest bstr-wrapped CBOR.
-
-    Only return the success error code QCBOR_ERR_NO_MORE_ITEMS here
-    when at the top level to allow other code below to process various
-    errors when out of bytes to decode and not at the top level. Note
-    that QCBORDecode_Finish() still needs to be called to be sure all
-    nesting levels were closed out.
-
-    TODO: really check for top level here?
    */
-   if(UsefulInputBuf_BytesUnconsumed(&(me->InBuf)) == 0 &&
-      DecodeNesting_IsCurrentAtTop(&(me->nesting))) {
+   if(UsefulInputBuf_BytesUnconsumed(&(me->InBuf)) == 0) {
       uReturn = QCBOR_ERR_NO_MORE_ITEMS;
       goto Done;
    }
@@ -1426,9 +1417,9 @@
    /* ==== Next: Process the item for descent, ascent, decrement... ==== */
    if(QCBORItem_IsMapOrArray(pDecodedItem)) {
       /*
-       If the new item is a map or array descend.
+       If the new item is a map or array, descend.
 
-       Empty maps and arrays descended into, but then ascended out
+       Empty indefinite length maps and arrays are descended into, but then ascended out
        of in the next chunk of code.
 
        Maps and arrays do count as items in the map/array that
@@ -1454,7 +1445,7 @@
          - An empty definite length map or array
          - An indefinite length map or array that might be empty or might not.
 
-       The Ascender does the work of decrementing the count for an
+       NestLevelAscender() does the work of decrementing the count for an
        definite length map/array and break detection for an indefinite
        length map/array. If the end of the map/array was reached, then
        it ascends nesting levels, possibly all the way to the top level.
@@ -2369,7 +2360,7 @@
           void               *pCBContext,
           QCBORItemCallback   pfCallback)
 {
-   QCBORError  uReturn;
+   QCBORError uReturn;
 
    QCBORDecodeNesting SaveNesting;
    DecodeNesting_PrepareForMapSearch(&(pMe->nesting), &SaveNesting);
@@ -2406,6 +2397,11 @@
       /* Get the item */
       QCBORItem Item;
       uReturn = QCBORDecode_GetNext(pMe, &Item);
+      if(uReturn == QCBOR_ERR_NO_MORE_ITEMS) {
+         /* Zero-length map.
+          TODO: understand this better. */
+         break;
+      }
       if(uReturn != QCBOR_SUCCESS) {
          /* Got non-well-formed CBOR */
          goto Done;
@@ -2790,6 +2786,11 @@
       return;
    }
 
+   if(Item.uNestingLevel == Item.uNextNestLevel) {
+      // Special case to increment nesting level for zero-length maps and arrays entered in bounded mode.
+      DecodeNesting_Descend(&(pMe->nesting), uType);
+   }
+
    pMe->uMapEndOffsetCache = MAP_OFFSET_CACHE_INVALID;
 
    QCBORError uErr = DecodeNesting_EnterBoundedMapOrArray(&(pMe->nesting),
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 2e1b586..c87f9e1 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -1612,7 +1612,7 @@
 }
 
 
-static int IsNotWellFormedError(QCBORError nErr)
+static bool IsNotWellFormedError(QCBORError nErr)
 {
    switch(nErr){
       case QCBOR_ERR_INDEFINITE_STRING_CHUNK:
@@ -1623,9 +1623,10 @@
       case QCBOR_ERR_BAD_BREAK:
       case QCBOR_ERR_EXTRA_BYTES:
       case QCBOR_ERR_BAD_INT:
-         return 1;
+      case QCBOR_ERR_NO_MORE_ITEMS: // TODO: really keep this?
+         return true;
       default:
-         return 0;
+         return false;
    }
 }
 
@@ -1745,39 +1746,39 @@
 
    // Definte length maps and arrays must be closed by having the right number of items
    // A definte length array that is supposed to have 1 item, but has none
-   { {(uint8_t[]){0x81}, 1}, QCBOR_ERR_HIT_END },
+   { {(uint8_t[]){0x81}, 1}, QCBOR_ERR_NO_MORE_ITEMS },
    // A definte length array that is supposed to have 2 items, but has only 1
-   { {(uint8_t[]){0x82, 0x00}, 2}, QCBOR_ERR_HIT_END },
+   { {(uint8_t[]){0x82, 0x00}, 2}, QCBOR_ERR_NO_MORE_ITEMS },
    // A definte length array that is supposed to have 511 items, but has only 1
    { {(uint8_t[]){0x9a, 0x01, 0xff, 0x00}, 4}, QCBOR_ERR_HIT_END },
    // A definte length map that is supposed to have 1 item, but has none
-   { {(uint8_t[]){0xa1}, 1}, QCBOR_ERR_HIT_END },
+   { {(uint8_t[]){0xa1}, 1}, QCBOR_ERR_NO_MORE_ITEMS },
    // A definte length map that is supposed to have s item, but has only 1
-   { {(uint8_t[]){0xa2, 0x01, 0x02}, 3}, QCBOR_ERR_HIT_END },
+   { {(uint8_t[]){0xa2, 0x01, 0x02}, 3}, QCBOR_ERR_NO_MORE_ITEMS },
 
 
    // Indefinte length maps and arrays must be ended by a break
    // Indefinite length array with zero items and no break
-   { {(uint8_t[]){0x9f}, 1}, QCBOR_ERR_HIT_END },
+   { {(uint8_t[]){0x9f}, 1}, QCBOR_ERR_NO_MORE_ITEMS },
    // Indefinite length array with two items and no break
-   { {(uint8_t[]){0x9f, 0x01, 0x02}, 3}, QCBOR_ERR_HIT_END },
+   { {(uint8_t[]){0x9f, 0x01, 0x02}, 3}, QCBOR_ERR_NO_MORE_ITEMS },
    // Indefinite length map with zero items and no break
-   { {(uint8_t[]){0xbf}, 1}, QCBOR_ERR_HIT_END },
+   { {(uint8_t[]){0xbf}, 1}, QCBOR_ERR_NO_MORE_ITEMS },
    // Indefinite length map with two items and no break
-   { {(uint8_t[]){0xbf, 0x01, 0x02, 0x01, 0x02}, 5}, QCBOR_ERR_HIT_END },
+   { {(uint8_t[]){0xbf, 0x01, 0x02, 0x01, 0x02}, 5}, QCBOR_ERR_NO_MORE_ITEMS },
 
 
    // Nested maps and arrays must be closed off (some extra nested test vectors)
    // Unclosed indefinite array containing a closed definite length array
-   { {(uint8_t[]){0x9f, 0x80, 0x00}, 3}, QCBOR_ERR_HIT_END },
+   { {(uint8_t[]){0x9f, 0x80, 0x00}, 3}, QCBOR_ERR_NO_MORE_ITEMS },
    // Definite length array containing an unclosed indefinite length array
-   { {(uint8_t[]){0x81, 0x9f}, 2}, QCBOR_ERR_HIT_END },
+   { {(uint8_t[]){0x81, 0x9f}, 2}, QCBOR_ERR_NO_MORE_ITEMS },
    // Deeply nested definite length arrays with deepest one unclosed
-   { {(uint8_t[]){0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81}, 9}, QCBOR_ERR_HIT_END },
+   { {(uint8_t[]){0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81}, 9}, QCBOR_ERR_NO_MORE_ITEMS }, // TODO: 23
    // Deeply nested indefinite length arrays with deepest one unclosed
-   { {(uint8_t[]){0x9f, 0x9f, 0x9f, 0x9f, 0x9f, 0xff, 0xff, 0xff, 0xff}, 9}, QCBOR_ERR_HIT_END },
+   { {(uint8_t[]){0x9f, 0x9f, 0x9f, 0x9f, 0x9f, 0xff, 0xff, 0xff, 0xff}, 9}, QCBOR_ERR_NO_MORE_ITEMS },
    // Mixed nesting with indefinite unclosed
-   { {(uint8_t[]){0x9f, 0x81, 0x9f, 0x81, 0x9f, 0x9f, 0xff, 0xff, 0xff}, 9}, QCBOR_ERR_HIT_END },
+   { {(uint8_t[]){0x9f, 0x81, 0x9f, 0x81, 0x9f, 0x9f, 0xff, 0xff, 0xff}, 9}, QCBOR_ERR_NO_MORE_ITEMS },
    // Mixed nesting with definite unclosed
    { {(uint8_t[]){0x9f, 0x82, 0x9f, 0x81, 0x9f, 0x9f, 0xff, 0xff, 0xff, 0xff}, 10}, QCBOR_ERR_BAD_BREAK },
    // TODO: a few more definite indefinite length combos and check with CBORbis.
@@ -1998,33 +1999,32 @@
 
    // Corrupt the UsefulInputBuf and see that
    // it reflected correctly for CBOR decoding
-   {
-      QCBORDecodeContext DCtx;
-      QCBORItem          Item;
-      QCBORError         nCBORError;
+   QCBORDecodeContext DCtx;
+   QCBORItem          Item;
+   QCBORError         uQCBORError;
 
-      QCBORDecode_Init(&DCtx,
-                       UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spSimpleValues),
-                       QCBOR_DECODE_MODE_NORMAL);
+   QCBORDecode_Init(&DCtx,
+                    UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spSimpleValues),
+                    QCBOR_DECODE_MODE_NORMAL);
 
-      if((nCBORError = QCBORDecode_GetNext(&DCtx, &Item)))
-         return (int32_t)nCBORError;
-      if(Item.uDataType != QCBOR_TYPE_ARRAY ||
-         Item.val.uCount != 10) {
-         // This wasn't supposed to happen
-         return -1;
-      }
+   if((uQCBORError = QCBORDecode_GetNext(&DCtx, &Item))) {
+      return (int32_t)uQCBORError;
+   }
+   if(Item.uDataType != QCBOR_TYPE_ARRAY || Item.val.uCount != 10) {
+      // This wasn't supposed to happen
+      return -1;
+   }
 
-      DCtx.InBuf.magic = 0; // Reach in and corrupt the UsefulInputBuf
+   DCtx.InBuf.magic = 0; // Reach in and corrupt the UsefulInputBuf
 
-      nCBORError = QCBORDecode_GetNext(&DCtx, &Item);
-      if(nCBORError != QCBOR_ERR_HIT_END) {
-         // Did not get back the error expected
-         return -2;
-      }
+   uQCBORError = QCBORDecode_GetNext(&DCtx, &Item);
+   if(uQCBORError != QCBOR_ERR_NO_MORE_ITEMS) {
+      // Did not get back the error expected
+      return -2;
    }
 
 /*
+ TODO: fix this
    This test is disabled until QCBOREncode_EncodeHead() is brought in so
  the size encoded can be tied to SIZE_MAX and work for all size CPUs.
 
@@ -3848,9 +3848,9 @@
                   0xFF, 0xFF, 0xC3, 0x4A, 0x01, 0x02, 0x03, 0x04, 0x05,
                   0x06, 0x07, 0x08, 0x09, 0x10}, 23}, QCBOR_ERR_BAD_EXP_AND_MANTISSA},
    // End of input
-   { {(uint8_t[]){0xC4, 0x82}, 2}, QCBOR_ERR_HIT_END},
+   { {(uint8_t[]){0xC4, 0x82}, 2}, QCBOR_ERR_NO_MORE_ITEMS},
    // End of input
-   { {(uint8_t[]){0xC4, 0x82, 0x01}, 3}, QCBOR_ERR_HIT_END},
+   { {(uint8_t[]){0xC4, 0x82, 0x01}, 3}, QCBOR_ERR_NO_MORE_ITEMS},
    // bad content for big num
    { {(uint8_t[]){0xC4, 0x82, 0x01, 0xc3, 0x01}, 5}, QCBOR_ERR_BAD_OPT_TAG},
    // bad content for big num
@@ -4041,6 +4041,9 @@
 0x84, 0x17, 0x19, 0x17, 0x70, 0x48, 0x67, 0x61, 0x6C, 0x61, 0x63, 0x74, 0x69, 0x63, 0x4B, 0x68, 0x61, 0x76, 0x65, 0x6E, 0x20, 0x74, 0x6F, 0x6B, 0x65, 0x6E};
 
 
+static const uint8_t spEmptyMap[] = {0xa0};
+
+static const uint8_t spEmptyInDefinteLengthMap[] = {0xbf, 0xff};
 
 int32_t EnterMapTest()
 {
@@ -4050,12 +4053,12 @@
    int32_t nReturn;
 
    (void)pValidMapIndefEncoded;
-   nReturn = EMap( UsefulBuf_FROM_BYTE_ARRAY_LITERAL(pValidMapIndefEncoded));
+   nReturn = EMap(UsefulBuf_FROM_BYTE_ARRAY_LITERAL(pValidMapIndefEncoded));
    if(nReturn) {
       return nReturn + 20000;
    }
 
-   nReturn = EMap( UsefulBuf_FROM_BYTE_ARRAY_LITERAL(pValidMapEncoded));
+   nReturn = EMap(UsefulBuf_FROM_BYTE_ARRAY_LITERAL(pValidMapEncoded));
     if(nReturn) {
        return nReturn;
     }
@@ -4135,7 +4138,38 @@
       return 2009;
    }
 
-   return 0;   
+
+   QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spEmptyMap), 0);
+   QCBORDecode_EnterMap(&DCtx);
+   // This will fail because the map is empty.
+   QCBORDecode_GetInt64InMapSZ(&DCtx, "another int",  &nDecodedInt2);
+   uErr = QCBORDecode_GetAndResetError(&DCtx);
+   if(uErr != QCBOR_ERR_NOT_FOUND){
+      return 2010;
+   }
+   QCBORDecode_ExitMap(&DCtx);
+   uErr = QCBORDecode_Finish(&DCtx);
+   if(uErr != QCBOR_SUCCESS){
+      return 2011;
+   }
+
+
+   // TODO: more testing of nested zero length maps; also test zero-length arrays
+   QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spEmptyInDefinteLengthMap), 0);
+   QCBORDecode_EnterMap(&DCtx);
+   // This will fail because the map is empty.
+   QCBORDecode_GetInt64InMapSZ(&DCtx, "another int",  &nDecodedInt2);
+   uErr = QCBORDecode_GetAndResetError(&DCtx);
+   if(uErr != QCBOR_ERR_NOT_FOUND){
+      return 2010;
+   }
+   QCBORDecode_ExitMap(&DCtx);
+   uErr = QCBORDecode_Finish(&DCtx);
+   if(uErr != QCBOR_SUCCESS){
+      return 2011;
+   }
+
+   return 0;
 }