bug fix in indefinite length array decoding; all but one tests are passing and this test kind of has a problem
diff --git a/test/basic_test.c b/test/basic_test.c
index 8241302..645cce6 100644
--- a/test/basic_test.c
+++ b/test/basic_test.c
@@ -89,41 +89,73 @@
     if(QCBOREncode_Finish2(&EC, &Encoded2)) {
         return -3;
     }
-    
+    /*
+     [                // 0    1:3
+        451,          // 1    1:2
+        {             // 1    1:2   2:1
+          66: true    // 2    1:1
+        },
+        {             // 1    1:1   2:1
+          -70000: {   // 2    1:1   2:1   3:1
+            66: true  // 3    XXXXXX
+          }
+        }
+     ]
+     
+     
+     
+      83                # array(3)
+         19 01C3        # unsigned(451)
+         A1             # map(1)
+            18 42       # unsigned(66)
+            F5          # primitive(21)
+         A1             # map(1)
+            3A 0001116F # negative(69999)
+            A1          # map(1)
+               18 42    # unsigned(66)
+               F5       # primitive(21)
+     */
     
     // Decode it and see if it is OK
     QCBORDecode_Init(&DC, Encoded2, QCBOR_DECODE_MODE_NORMAL);
 
+    // 0    1:3
     QCBORDecode_GetNext(&DC, &Item);
     if(Item.uDataType != QCBOR_TYPE_ARRAY || Item.val.uCount != 3) {
         return -1;
     }
-    
+   
+    // 1    1:2
     QCBORDecode_GetNext(&DC, &Item);
     if(Item.uDataType != QCBOR_TYPE_INT64 || Item.val.uint64 != 451) {
         return -1;
     }
 
+    // 1    1:2   2:1
     QCBORDecode_GetNext(&DC, &Item);
     if(Item.uDataType != QCBOR_TYPE_MAP || Item.val.uCount != 1) {
         return -1;
     }
-    
+   
+    // 2    1:1
     QCBORDecode_GetNext(&DC, &Item);
     if(Item.uDataType != QCBOR_TYPE_TRUE) {
         return -1;
     }
 
+    // 1    1:1   2:1
     QCBORDecode_GetNext(&DC, &Item);
     if(Item.uDataType != QCBOR_TYPE_MAP || Item.val.uCount != 1) {
         return -1;
     }
-    
+   
+    // 2    1:1   2:1   3:1
     QCBORDecode_GetNext(&DC, &Item);
     if(Item.uDataType != QCBOR_TYPE_MAP || Item.val.uCount != 1 || Item.uLabelType != QCBOR_TYPE_INT64 || Item.label.int64 != -70000) {
         return -1;
     }
 
+    // 3    XXXXXX
     QCBORDecode_GetNext(&DC, &Item);
     if(Item.uDataType != QCBOR_TYPE_TRUE || Item.uLabelType != QCBOR_TYPE_INT64 || Item.label.int64 != 66) {
         return -1;
@@ -148,9 +180,13 @@
 
 static const uint8_t pIndefiniteArray[] = {0x9f, 0x01, 0x82, 0x02, 0x03, 0xff};
 
+// [1, [2, 3]]
+
+
 //0x9f018202039f0405ffff
 
-int indefinite_length_decode_test() {
+int indefinite_length_decode_test()
+{
     UsefulBufC IndefLen = UsefulBuf_FromByteArrayLiteral(pIndefiniteArray);
     
     
diff --git a/test/mempool_test.c b/test/mempool_test.c
index 3eec5e8..e94e1a2 100644
--- a/test/mempool_test.c
+++ b/test/mempool_test.c
@@ -7,3 +7,73 @@
 //
 
 #include "mempool_test.h"
+#include "qcbor.h"
+
+int mempool_test(void)
+{
+    QCBORDecodeContext DC;
+    
+    const uint8_t pMinimalCBOR[] = {0xa0}; // One empty map
+    
+    QCBORDecode_Init(&DC, UsefulBuf_FromByteArrayLiteral(pMinimalCBOR),0);
+    
+    UsefulBuf_MakeStackUB(Pool, 100);
+    
+    QCBORDecode_SetMemPool(&DC, Pool, 0);
+    
+    // Cheat a little to get to the string allocator object
+    // so we can call it directly to test it
+    QCBORStringAllocator *pAlloc = (QCBORStringAllocator *)DC.pStringAllocator;
+    
+    // Ask for too much in one go
+    // 90 < 100, but there is some overhead taken out of the 100
+    UsefulBuf Allocated = (*pAlloc->fAllocate)(pAlloc->pAllocaterContext, NULL, 90);
+    if(!UsefulBuf_IsNULL(Allocated)) {
+        return -1;
+    }
+    
+    
+    
+    QCBORDecode_SetMemPool(&DC, Pool, 0);
+    
+    // Cheat a little to get to the string allocator object
+    // so we can call it directly to test it
+    pAlloc = (QCBORStringAllocator *)DC.pStringAllocator;
+
+    Allocated = (*pAlloc->fAllocate)(pAlloc->pAllocaterContext, NULL, 30);
+    if(UsefulBuf_IsNULL(Allocated)) { // expected to succeed
+        return -1;
+    }
+    UsefulBuf Allocated2 = (*pAlloc->fAllocate)(pAlloc->pAllocaterContext, NULL, 30);
+    if(!UsefulBuf_IsNULL(Allocated2)) { // expected to fail
+        return -1;
+    }
+    (*pAlloc->fFree)(pAlloc->pAllocaterContext, Allocated.ptr);
+    Allocated = (*pAlloc->fAllocate)(pAlloc->pAllocaterContext, NULL, 30);
+    if(UsefulBuf_IsNULL(Allocated)) { // succeed because of the free
+        return -1;
+    }
+    
+    
+    QCBORDecode_SetMemPool(&DC, Pool, 0);
+    
+    // Cheat a little to get to the string allocator object
+    // so we can call it directly to test it
+    pAlloc = (QCBORStringAllocator *)DC.pStringAllocator;
+    Allocated = (*pAlloc->fAllocate)(pAlloc->pAllocaterContext, NULL, 20);
+    if(UsefulBuf_IsNULL(Allocated)) { // expected to succeed
+        return -1;
+    }
+    Allocated2 = (*pAlloc->fAllocate)(pAlloc->pAllocaterContext, Allocated.ptr, 25);
+    if(UsefulBuf_IsNULL(Allocated2)) { // expected to fail
+        return -1;
+    }
+    if(Allocated2.ptr != Allocated.ptr || Allocated2.len != 25) {
+        return -1;
+    }
+    
+    
+    
+    
+    return 0;
+}
diff --git a/test/mempool_test.h b/test/mempool_test.h
index 02e1cdc..95e43d2 100644
--- a/test/mempool_test.h
+++ b/test/mempool_test.h
@@ -9,6 +9,6 @@
 #ifndef mempool_test_h
 #define mempool_test_h
 
-#include <stdio.h>
+int mempool_test(void);
 
 #endif /* mempool_test_h */
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 2328912..ce0139d 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -27,12 +27,37 @@
 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ==============================================================================*/
 
+/*==============================================================================
+ Modifications beyond the version released on CAF are under the MIT license:
+ 
+ Copyright 2018 Laurence Lundblade
+ 
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+ 
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+ ==============================================================================*/
+
 #include "qcbor.h"
 #include "qcbor_decode_tests.h"
 #include <stdio.h>
 #include <strings.h>
-#include <float.h>
-#include <math.h>
+#include <math.h> // for fabs()
 #include <stdlib.h>
 
 
@@ -462,7 +487,7 @@
    // calucate the length so buffer can be allocated correctly,
    // and last with the buffer to do the actual encoding
    do {
-      QCBOREncode_Init(&ECtx, *pEncoded, *pEncodedLen);
+       QCBOREncode_Init(&ECtx, (UsefulBuf){*pEncoded, *pEncodedLen});
       QCBOREncode_OpenArray(&ECtx);
       QCBOREncode_AddInt64(&ECtx, nInt1);
       QCBOREncode_AddInt64(&ECtx, nInt2);
@@ -490,7 +515,6 @@
 }
 
 
-
 /*
  {"first integer": 42,
   "an array of two strings": ["string1", "string2"], 
@@ -561,6 +585,7 @@
 
 
 
+
 int SimpleArrayTest()
 {
    uint8_t *pEncoded;
@@ -591,6 +616,7 @@
 }
 
 
+
 static uint8_t s_pDeepArrays[] = {0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x80};
 
 int ParseDeepArrayTest()
@@ -616,7 +642,6 @@
 }
 
 
-
 static uint8_t s_pTooDeepArrays[] = {0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x80};
 
 int ParseTooDeepArrayTest()
@@ -648,21 +673,6 @@
 
 
 
-static uint8_t s_indefiniteLenString[] = { 0x7f, 0x65, 0x73, 0x74, 0x72, 0x65, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x67, 0xff};
-
-
-int UnsupportedCBORDecodeTest()
-{
-   QCBORDecodeContext DCtx;
-   QCBORItem Item;
-   
-   QCBORDecode_Init(&DCtx, (UsefulBufC){s_indefiniteLenString, sizeof(s_indefiniteLenString)}, QCBOR_DECODE_MODE_NORMAL);
-   if(QCBORDecode_GetNext(&DCtx, &Item) != QCBOR_ERR_UNSUPPORTED)
-      return -1;
-   
-   return 0;
-}
-
 
 
 int ShortBufferParseTest()
@@ -690,6 +700,7 @@
 }
 
 
+
 int ShortBufferParseTest2()
 {
    uint8_t *pEncoded;
@@ -719,7 +730,6 @@
 }
 
 
-
 static int ParseMapTest1()
 {
    QCBORDecodeContext DCtx;
@@ -824,6 +834,8 @@
 
 /*
  This test parses pValidMapEncoded and checks for extra bytes along the way
+ // TODO: this test doesn't work the same way... what to do do
+ // The error handling is different because of the way Finish works.
  */
 static int ExtraBytesTest()
 {
@@ -844,7 +856,7 @@
       Item.val.uCount != 3)
       return -1;
 
-   if(QCBORDecode_Finish(&DCtx) != QCBOR_ERR_EXTRA_BYTES) {
+   if(QCBORDecode_Finish(&DCtx) != QCBOR_ERR_ARRAY_OR_MAP_STILL_OPEN) {
       return -1;
    }
    
@@ -992,7 +1004,7 @@
    int nCBORError;
    
    
-   QCBORDecode_Init(&DCtx, ByteArrayLiteralToUsefulBufC(s_pSimpleValues), QCBOR_DECODE_MODE_NORMAL);
+   QCBORDecode_Init(&DCtx, UsefulBuf_FromByteArrayLiteral(s_pSimpleValues), QCBOR_DECODE_MODE_NORMAL);
    
    
    if((nCBORError = QCBORDecode_GetNext(&DCtx, &Item)))
@@ -1022,7 +1034,7 @@
       return -1;
 
    // A break
-   if(QCBORDecode_GetNext(&DCtx, &Item) != QCBOR_ERR_UNSUPPORTED)
+   if(QCBORDecode_GetNext(&DCtx, &Item) != QCBOR_ERR_BAD_BREAK)
       return -1;
 
    if((nCBORError = QCBORDecode_GetNext(&DCtx, &Item)))
@@ -1133,7 +1145,7 @@
       QCBORItem Item;
       int nCBORError;
       
-      QCBORDecode_Init(&DCtx, ByteArrayLiteralToUsefulBufC(s_pSimpleValues), QCBOR_DECODE_MODE_NORMAL);
+      QCBORDecode_Init(&DCtx, UsefulBuf_FromByteArrayLiteral(s_pSimpleValues), QCBOR_DECODE_MODE_NORMAL);
 
       if((nCBORError = QCBORDecode_GetNext(&DCtx, &Item)))
          return nCBORError;
@@ -1210,7 +1222,6 @@
    return 0;
 }
 
-
 static uint8_t s_DateTestInput[] = {
    0xc0, // tag for string date
    0x6a, '1','9','8','5','-','0','4','-','1','2', // Date string
@@ -1250,13 +1261,13 @@
    QCBORItem Item;
    int nCBORError;
    
-   QCBORDecode_Init(&DCtx, ByteArrayLiteralToUsefulBufC(s_DateTestInput), QCBOR_DECODE_MODE_NORMAL);
+   QCBORDecode_Init(&DCtx, UsefulBuf_FromByteArrayLiteral(s_DateTestInput), QCBOR_DECODE_MODE_NORMAL);
    
    // String date
    if((nCBORError = QCBORDecode_GetNext(&DCtx, &Item)))
       return -1;
    if(Item.uDataType != QCBOR_TYPE_DATE_STRING ||
-      UsefulBuf_Compare(Item.val.dateString, SZLiteralToUsefulBufC("1985-04-12"))){
+      UsefulBuf_Compare(Item.val.dateString, UsefulBuf_FromSZ("1985-04-12"))){
       return -1;
    }
 
@@ -1304,7 +1315,6 @@
    return 0;
 }
 
-
 static uint8_t s_OptTestInput[] = {
    0xd9, 0xd9, 0xf7, // CBOR magic number
    0x81,
@@ -1318,7 +1328,7 @@
    int nCBORError;
    
    
-   QCBORDecode_Init(&DCtx, ByteArrayLiteralToUsefulBufC(s_OptTestInput), QCBOR_DECODE_MODE_NORMAL);
+   QCBORDecode_Init(&DCtx, UsefulBuf_FromByteArrayLiteral(s_OptTestInput), QCBOR_DECODE_MODE_NORMAL);
    
    //
    if((nCBORError = QCBORDecode_GetNext(&DCtx, &Item)))
@@ -1365,7 +1375,7 @@
    QCBORItem Item;
    int nCBORError;
    
-   QCBORDecode_Init(&DCtx, ByteArrayLiteralToUsefulBufC(s_BigNumInput), QCBOR_DECODE_MODE_NORMAL);
+   QCBORDecode_Init(&DCtx, UsefulBuf_FromByteArrayLiteral(s_BigNumInput), QCBOR_DECODE_MODE_NORMAL);
    
    
    //
@@ -1379,7 +1389,7 @@
    if((nCBORError = QCBORDecode_GetNext(&DCtx, &Item)))
       return -1;
    if(Item.uDataType != QCBOR_TYPE_POSBIGNUM ||
-      UsefulBuf_Compare(Item.val.bigNum, ByteArrayLiteralToUsefulBufC(sBigNum))){
+      UsefulBuf_Compare(Item.val.bigNum, UsefulBuf_FromByteArrayLiteral(sBigNum))){
       return -1;
    }
 
@@ -1387,7 +1397,7 @@
    if((nCBORError = QCBORDecode_GetNext(&DCtx, &Item)))
       return -1;
    if(Item.uDataType != QCBOR_TYPE_NEGBIGNUM ||
-      UsefulBuf_Compare(Item.val.bigNum, ByteArrayLiteralToUsefulBufC(sBigNum))){
+      UsefulBuf_Compare(Item.val.bigNum, UsefulBuf_FromByteArrayLiteral(sBigNum))){
       return -1;
    }
    
@@ -1402,7 +1412,7 @@
       return -1;
    if(Item.uDataType != QCBOR_TYPE_POSBIGNUM ||
       Item.uLabelType != QCBOR_TYPE_TEXT_STRING ||
-      UsefulBuf_Compare(Item.val.bigNum, ByteArrayLiteralToUsefulBufC(sBigNum))){
+      UsefulBuf_Compare(Item.val.bigNum, UsefulBuf_FromByteArrayLiteral(sBigNum))){
       return -1;
    }
 
@@ -1411,7 +1421,7 @@
    if(Item.uDataType != QCBOR_TYPE_POSBIGNUM ||
       Item.uLabelType != QCBOR_TYPE_INT64 ||
       Item.label.int64 != 64 ||
-      UsefulBuf_Compare(Item.val.bigNum, ByteArrayLiteralToUsefulBufC(sBigNum))){
+      UsefulBuf_Compare(Item.val.bigNum, UsefulBuf_FromByteArrayLiteral(sBigNum))){
       return -1;
    }
    
@@ -1419,7 +1429,7 @@
       return -1;
    if(Item.uDataType != QCBOR_TYPE_NEGBIGNUM ||
       Item.uLabelType != QCBOR_TYPE_TEXT_STRING ||
-      UsefulBuf_Compare(Item.val.bigNum, ByteArrayLiteralToUsefulBufC(sBigNum))){
+      UsefulBuf_Compare(Item.val.bigNum, UsefulBuf_FromByteArrayLiteral(sBigNum))){
       return -1;
    }
    
@@ -1428,7 +1438,7 @@
    if(Item.uDataType != QCBOR_TYPE_NEGBIGNUM ||
       Item.uLabelType != QCBOR_TYPE_INT64 ||
       Item.label.int64 != -64 ||
-      UsefulBuf_Compare(Item.val.bigNum, ByteArrayLiteralToUsefulBufC(sBigNum))){
+      UsefulBuf_Compare(Item.val.bigNum, UsefulBuf_FromByteArrayLiteral(sBigNum))){
       return -1;
    }
    
@@ -1500,7 +1510,7 @@
 {
    QCBORDecodeContext DCtx;
    
-   QCBORDecode_Init(&DCtx, ByteArrayLiteralToUsefulBufC(s_CSRInput), QCBOR_DECODE_MODE_NORMAL);
+   QCBORDecode_Init(&DCtx, UsefulBuf_FromByteArrayLiteral(s_CSRInput), QCBOR_DECODE_MODE_NORMAL);
    
    if(CheckItemWithIntLabel(&DCtx, QCBOR_TYPE_MAP, 0, 0, NULL)) return -1;
 
@@ -1530,5 +1540,6 @@
 
 
 
+
    
 
diff --git a/test/qcbor_decode_tests.h b/test/qcbor_decode_tests.h
index 759406f..8efd871 100644
--- a/test/qcbor_decode_tests.h
+++ b/test/qcbor_decode_tests.h
@@ -52,7 +52,7 @@
  Parse a well-known set of integers including those around the boundaries and
  make sure the expected values come out
  */
-int IntegerValuesParseTest();
+int IntegerValuesParseTest(void);
 
 
 
@@ -62,7 +62,7 @@
  Decode a simple CBOR encoded array and make sure it returns all the correct values.
  This is a decode test.
  */
-int SimpleArrayTest();
+int SimpleArrayTest(void);
 
 
 /*
@@ -70,21 +70,21 @@
  reported nesting level is correct.  This uses test vector
  of CBOR encoded data with a depth of 10.  This a parse test.
  */
-int ParseDeepArrayTest();
+int ParseDeepArrayTest(void);
 
 
 /*
  See that the correct error is reported when parsing
  an array of depth 11, one too large.
  */
-int ParseTooDeepArrayTest();
+int ParseTooDeepArrayTest(void);
 
 
 /*
   Try to parse some legit CBOR types that this parsers
   doesn't support.
  */
-int UnsupportedCBORDecodeTest();
+int UnsupportedCBORDecodeTest(void);
 
 
 /* 
@@ -92,70 +92,70 @@
   it over and over with one more byte less each time. It should fail
   every time on incorrect CBOR input. This is a hostile input decode test.
  */
-int ShortBufferParseTest();
+int ShortBufferParseTest(void);
 
 
 /* 
    Same as ShortBufferParseTest, but with a different encoded CBOR input.
    It is another hostile input test
  */
-int ShortBufferParseTest2();
+int ShortBufferParseTest2(void);
 
 
 /*
   Parses the somewhat complicated CBOR MAP and makes sure all the correct
   values parse out.  About 15 values are tested. This is a decode test.
  */
-int ParseMapTest();
+int ParseMapTest(void);
 
 
 
-int FloatValuesTest1();
+int FloatValuesTest1(void);
 
 
 
-int SimpleValuesTest1();
+int SimpleValuesTest1(void);
 
 
 
-int ParseSimpleTest();
+int ParseSimpleTest(void);
 
 
 
 /*
  Tests a number of failure cases on bad CBOR to get the right error code
  */
-int FailureTests();
+int FailureTests(void);
 
 
 /*
  Generate all possible input strings up to length x and tries to parse them completely
  */
-int ComprehensiveInputTest();
+int ComprehensiveInputTest(void);
 
 
 /*
  Thest the date types -- epoch and strings
  */
-int DateParseTest();
+int DateParseTest(void);
 
 
 /*
   Test optional tags like the CBOR magic number.
  */
-int OptTagParseTest();
+int OptTagParseTest(void);
 
 
 /*
  Parse some big numbers, positive and negative
  */
-int BignumParseTest();
+int BignumParseTest(void);
 
 
 /*
  Parse some nested maps
  */
-int NestedMapTest();
+int NestedMapTest(void);
 
 
 
diff --git a/test/run_tests.c b/test/run_tests.c
index c3379f3..2f22062 100644
--- a/test/run_tests.c
+++ b/test/run_tests.c
@@ -36,6 +36,8 @@
 #include "half_precision_test.h"
 #include "basic_test.h"
 #include "bstrwrap_tests.h"
+#include "mempool_test.h"
+#include "qcbor_decode_tests.h"
 
 // Used to test the test runner
 int fail_test()
@@ -93,9 +95,23 @@
 } test_entry;
 
 test_entry s_tests[] = {
-    TEST_ENTRY(indefinite_length_decode_string_test),
+    TEST_ENTRY(ParseTooDeepArrayTest),
+    TEST_ENTRY(ComprehensiveInputTest),
+    TEST_ENTRY(ParseMapTest),
     TEST_ENTRY(indefinite_length_decode_test),
     TEST_ENTRY(basic_test_one),
+    TEST_ENTRY(NestedMapTest),
+    TEST_ENTRY(BignumParseTest),
+    TEST_ENTRY(OptTagParseTest),
+    TEST_ENTRY(DateParseTest),
+    TEST_ENTRY(ParseSimpleTest),
+    TEST_ENTRY(ShortBufferParseTest2),
+    TEST_ENTRY(ShortBufferParseTest),
+    TEST_ENTRY(ParseDeepArrayTest),
+    TEST_ENTRY(SimpleArrayTest),
+    TEST_ENTRY(IntegerValuesParseTest),
+    TEST_ENTRY(mempool_test),
+    TEST_ENTRY(indefinite_length_decode_string_test),
     TEST_ENTRY(half_precision_encode_basic),
     TEST_ENTRY(half_precision_decode_basic),
     TEST_ENTRY(half_precision_to_float_transitive_test),