fixed bug in indefinite length map decoding; more indefinite length map tests
diff --git a/cmd_line_main.c b/cmd_line_main.c
index fbf9e22..cacc095 100644
--- a/cmd_line_main.c
+++ b/cmd_line_main.c
@@ -41,7 +41,7 @@
 int main(int argc, const char * argv[])
 {
     (void)argc; // Suppress unused warning
-    (void)argv; // Supress unused warning
+    (void)argv; // Suppress unused warning
    
     int nNumTestsFailed = run_tests(&fputs_wrapper, stdout, NULL);
 
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index 0f76963..2ec7a68 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -833,6 +833,10 @@
    if(nReturn)
       goto Done;
    
+   if(pDecodedItem->uDataType == QCBOR_TYPE_BREAK) {
+      goto Done;
+   }
+   
    // If in a map and the right decoding mode, get the label
    if(DecodeNesting_TypeIsMap(&(me->nesting)) && me->uDecodeMode != QCBOR_DECODE_MODE_MAP_AS_ARRAY) {
       // In a map and caller wants maps decoded, not treated as arrays
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 9bdfe79..a2d53a9 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -1513,6 +1513,36 @@
 }
 
 
+// Same code checks definite and indefinite length versions of the map
+static int CheckCSRMaps(QCBORDecodeContext *pDC)
+{
+   if(CheckItemWithIntLabel(pDC, QCBOR_TYPE_MAP, 0, 0, NULL)) return -1;
+   
+   if(CheckItemWithIntLabel(pDC, QCBOR_TYPE_MAP, 1, -23, NULL)) return -1;
+   
+   if(CheckItemWithIntLabel(pDC, QCBOR_TYPE_MAP, 2, -20, NULL)) return -1;
+   
+   if(CheckItemWithIntLabel(pDC, QCBOR_TYPE_TEXT_STRING, 3, -18, NULL)) return -1;
+   if(CheckItemWithIntLabel(pDC, QCBOR_TYPE_TEXT_STRING, 3, -17, NULL)) return -1;
+   if(CheckItemWithIntLabel(pDC, QCBOR_TYPE_TEXT_STRING, 3, -15, NULL)) return -1;
+   if(CheckItemWithIntLabel(pDC, QCBOR_TYPE_TEXT_STRING, 3, -16, NULL)) return -1;
+   if(CheckItemWithIntLabel(pDC, QCBOR_TYPE_TEXT_STRING, 3, -14, NULL)) return -1;
+   
+   if(CheckItemWithIntLabel(pDC, QCBOR_TYPE_MAP, 2, -19, NULL)) return -1;
+   if(CheckItemWithIntLabel(pDC, QCBOR_TYPE_MAP, 3, -11, NULL)) return -1;
+   
+   if(CheckItemWithIntLabel(pDC, QCBOR_TYPE_INT64, 4, -9, NULL)) return -1;
+   if(CheckItemWithIntLabel(pDC, QCBOR_TYPE_BYTE_STRING, 3, -10, NULL)) return -1;
+   
+   if(CheckItemWithIntLabel(pDC, QCBOR_TYPE_MAP, 1, -22, NULL)) return -1;
+   if(CheckItemWithIntLabel(pDC, QCBOR_TYPE_INT64, 2, -5, NULL)) return -1;
+   
+   if(QCBORDecode_Finish(pDC)) return -2;
+   
+   return 0;
+}
+
+
 /*
 // cbor.me decoded output
 {
@@ -1537,6 +1567,7 @@
 }
  */
 
+
 static uint8_t s_CSRInput[] = {
    0xa2, 0x36, 0xa2, 0x33, 0xa5, 0x31, 0x6c, 0x4f,
    0x72, 0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74,
@@ -1554,30 +1585,31 @@
    
    QCBORDecode_Init(&DCtx, UsefulBuf_FromByteArrayLiteral(s_CSRInput), QCBOR_DECODE_MODE_NORMAL);
    
-   if(CheckItemWithIntLabel(&DCtx, QCBOR_TYPE_MAP, 0, 0, NULL)) return -1;
-
-   if(CheckItemWithIntLabel(&DCtx, QCBOR_TYPE_MAP, 1, -23, NULL)) return -1;
-
-   if(CheckItemWithIntLabel(&DCtx, QCBOR_TYPE_MAP, 2, -20, NULL)) return -1;
-
-   if(CheckItemWithIntLabel(&DCtx, QCBOR_TYPE_TEXT_STRING, 3, -18, NULL)) return -1;
-   if(CheckItemWithIntLabel(&DCtx, QCBOR_TYPE_TEXT_STRING, 3, -17, NULL)) return -1;
-   if(CheckItemWithIntLabel(&DCtx, QCBOR_TYPE_TEXT_STRING, 3, -15, NULL)) return -1;
-   if(CheckItemWithIntLabel(&DCtx, QCBOR_TYPE_TEXT_STRING, 3, -16, NULL)) return -1;
-   if(CheckItemWithIntLabel(&DCtx, QCBOR_TYPE_TEXT_STRING, 3, -14, NULL)) return -1;
-
-   if(CheckItemWithIntLabel(&DCtx, QCBOR_TYPE_MAP, 2, -19, NULL)) return -1;
-   if(CheckItemWithIntLabel(&DCtx, QCBOR_TYPE_MAP, 3, -11, NULL)) return -1;
-   
-   if(CheckItemWithIntLabel(&DCtx, QCBOR_TYPE_INT64, 4, -9, NULL)) return -1;
-   if(CheckItemWithIntLabel(&DCtx, QCBOR_TYPE_BYTE_STRING, 3, -10, NULL)) return -1;
-   
-   if(CheckItemWithIntLabel(&DCtx, QCBOR_TYPE_MAP, 1, -22, NULL)) return -1;
-   if(CheckItemWithIntLabel(&DCtx, QCBOR_TYPE_INT64, 2, -5, NULL)) return -1;
-   
-   return 0;
+   return CheckCSRMaps(&DCtx);
 }
 
+// Same map as above, but using indefinite lengths
+static uint8_t s_CSRInputIndefLen[] = {
+   0xbf, 0x36, 0xbf, 0x33, 0xbf, 0x31, 0x6c, 0x4f,
+   0x72, 0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74,
+   0x69, 0x6f, 0x6e, 0x30, 0x63, 0x53, 0x53, 0x47,
+   0x2e, 0x69, 0x43, 0x6f, 0x6e, 0x66, 0x75, 0x73,
+   0x69, 0x6f, 0x6e, 0x2f, 0x69, 0x53, 0x61, 0x6e,
+   0x20, 0x44, 0x69, 0x65, 0x67, 0x6f, 0x2d, 0x62,
+   0x55, 0x53,  0xff, 0x32, 0xbf, 0x2a, 0xbf, 0x28,  0x26, 0xff,
+   0x29, 0x4a, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
+   0x07, 0x08, 0x09, 0x0a, 0xff, 0xff, 0x35, 0xbf, 0x24, 0x22, 0xff, 0xff};
+
+int NestedMapTestIndefLen()
+{
+   QCBORDecodeContext DCtx;
+   
+   QCBORDecode_Init(&DCtx, UsefulBuf_FromByteArrayLiteral(s_CSRInputIndefLen), QCBOR_DECODE_MODE_NORMAL);
+   
+   return CheckCSRMaps(&DCtx);
+}
+
+
 
 static UsefulBufC make_nested_indefinite_arrays(int n, UsefulBuf Storage)
 {
diff --git a/test/qcbor_decode_tests.h b/test/qcbor_decode_tests.h
index 52e64c5..5168466 100644
--- a/test/qcbor_decode_tests.h
+++ b/test/qcbor_decode_tests.h
@@ -157,6 +157,8 @@
  */
 int NestedMapTest(void);
 
+int NestedMapTestIndefLen(void);
+
 
 int indefinite_length_decode_test(void);
 int indefinite_length_decode_string_test(void);
diff --git a/test/run_tests.c b/test/run_tests.c
index 1aee18b..ad3f7b7 100644
--- a/test/run_tests.c
+++ b/test/run_tests.c
@@ -127,6 +127,7 @@
     TEST_ENTRY(ParseTooDeepArrayTest),
     TEST_ENTRY(ComprehensiveInputTest),
     TEST_ENTRY(ParseMapTest),
+    TEST_ENTRY(NestedMapTestIndefLen),
     TEST_ENTRY(indefinite_length_decode_test),
     TEST_ENTRY(basic_encode_test),
     TEST_ENTRY(NestedMapTest),