malloc-based string allocator is fixed, tested and working. Other cleanup
diff --git a/Makefile b/Makefile
index 6e7745f..bbfec48 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,9 @@
 CFLAGS=-I inc -I test -Os -Wall -Werror -pedantic-errors -Wextra -Wshadow
 
-QCBOR_OBJ=src/UsefulBuf.o src/qcbor_encode.o src/qcbor_decode.o src/ieee754.o
+QCBOR_OBJ=src/UsefulBuf.o src/qcbor_encode.o src/qcbor_decode.o src/ieee754.o src/qcbor_decode_malloc.o
 
 TEST_OBJ=test/UsefulBuf_Tests.o test/qcbor_encode_tests.o test/qcbor_decode_tests.o test/run_tests.o \
-  test/float_tests.o test/half_to_double_from_rfc7049.o
+  test/float_tests.o test/half_to_double_from_rfc7049.o test/qcbor_decode_malloc_tests.o
 
 CMD_LINE_OBJ=$(QCBOR_OBJ) $(TEST_OBJ) cmd_line_main.o
 
@@ -14,14 +14,16 @@
 src/qcbor_decode.o:	inc/UsefulBuf.h inc/qcbor.h src/ieee754.h
 src/qcbor_encode.o:	inc/UsefulBuf.h inc/qcbor.h src/ieee754.h
 src/iee754.o:	src/ieee754.h 
+src/qcbor_malloc_decode.o:	inc/qcbor.h
 
 test/run_tests.o:	test/UsefulBuf_Tests.h test/float_tests.h test/run_tests.h test/qcbor_encode_tests.h\
-    test/qcbor_decode_tests.h
+    test/qcbor_decode_tests.h test/qcbor_decode_malloc_tests.h
 test/UsefulBuf_Tests.o:	test/UsefulBuf_Tests.h inc/qcbor.h inc/UsefulBuf.h
 test/qcbor_encode_tests.o:	test/qcbor_encode_tests.h inc/qcbor.h inc/UsefulBuf.h
 test/qcbor_decode_tests.o:	test/qcbor_decode_tests.h inc/qcbor.h inc/UsefulBuf.h
 test/float_tests.o:	inc/qcbor.h inc/UsefulBuf.h test/float_tests.h test/half_to_double_from_rfc7049.h
 test/half_to_double_from_rfc7049.o:	test/half_to_double_from_rfc7049.h
+test/qcbor_decode_malloc_test.o:	test/qcbor_decode_malloc_tests.h
 
 cmd_line_main.o:	test/run_tests.h
 
diff --git a/QCBOR.xcodeproj/project.pbxproj b/QCBOR.xcodeproj/project.pbxproj
index 6375f48..08c4e91 100644
--- a/QCBOR.xcodeproj/project.pbxproj
+++ b/QCBOR.xcodeproj/project.pbxproj
@@ -11,6 +11,7 @@
 		0FA9BEB7216CE6CA00BA646B /* qcbor_decode_tests.c in Sources */ = {isa = PBXBuildFile; fileRef = 0FA9BEB5216CE6CA00BA646B /* qcbor_decode_tests.c */; };
 		0FA9BEBA216DC7AD00BA646B /* qcbor_encode_tests.c in Sources */ = {isa = PBXBuildFile; fileRef = 0FA9BEB8216DC7AD00BA646B /* qcbor_encode_tests.c */; };
 		0FA9BEBD216DE31700BA646B /* UsefulBuf_Tests.c in Sources */ = {isa = PBXBuildFile; fileRef = 0FA9BEBC216DE31700BA646B /* UsefulBuf_Tests.c */; };
+		0FA9BF9021788F4A00BA646B /* qcbor_decode_malloc_tests.c in Sources */ = {isa = PBXBuildFile; fileRef = 0FA9BF8F21788F4A00BA646B /* qcbor_decode_malloc_tests.c */; };
 		E73B57592161CA690080D658 /* ieee754.c in Sources */ = {isa = PBXBuildFile; fileRef = E73B57582161CA690080D658 /* ieee754.c */; };
 		E73B575E2161CA7C0080D658 /* float_tests.c in Sources */ = {isa = PBXBuildFile; fileRef = E73B575A2161CA7C0080D658 /* float_tests.c */; };
 		E73B575F2161CA7C0080D658 /* half_to_double_from_rfc7049.c in Sources */ = {isa = PBXBuildFile; fileRef = E73B575D2161CA7C0080D658 /* half_to_double_from_rfc7049.c */; };
@@ -41,6 +42,8 @@
 		0FA9BEB9216DC7AD00BA646B /* qcbor_encode_tests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = qcbor_encode_tests.h; path = test/qcbor_encode_tests.h; sourceTree = "<group>"; };
 		0FA9BEBB216DE31700BA646B /* UsefulBuf_Tests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UsefulBuf_Tests.h; path = test/UsefulBuf_Tests.h; sourceTree = "<group>"; };
 		0FA9BEBC216DE31700BA646B /* UsefulBuf_Tests.c */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 3; lastKnownFileType = sourcecode.c.c; name = UsefulBuf_Tests.c; path = test/UsefulBuf_Tests.c; sourceTree = "<group>"; tabWidth = 3; };
+		0FA9BF8E21788F4A00BA646B /* qcbor_decode_malloc_tests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = qcbor_decode_malloc_tests.h; path = test/qcbor_decode_malloc_tests.h; sourceTree = "<group>"; };
+		0FA9BF8F21788F4A00BA646B /* qcbor_decode_malloc_tests.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = qcbor_decode_malloc_tests.c; path = test/qcbor_decode_malloc_tests.c; sourceTree = "<group>"; };
 		E73B57572161CA680080D658 /* ieee754.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ieee754.h; path = src/ieee754.h; sourceTree = "<group>"; };
 		E73B57582161CA690080D658 /* ieee754.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ieee754.c; path = src/ieee754.c; sourceTree = "<group>"; };
 		E73B575A2161CA7C0080D658 /* float_tests.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = float_tests.c; path = test/float_tests.c; sourceTree = "<group>"; };
@@ -127,6 +130,8 @@
 				E73B575C2161CA7C0080D658 /* float_tests.h */,
 				E73B575D2161CA7C0080D658 /* half_to_double_from_rfc7049.c */,
 				E73B575B2161CA7C0080D658 /* half_to_double_from_rfc7049.h */,
+				0FA9BF8E21788F4A00BA646B /* qcbor_decode_malloc_tests.h */,
+				0FA9BF8F21788F4A00BA646B /* qcbor_decode_malloc_tests.c */,
 			);
 			name = test;
 			sourceTree = "<group>";
@@ -187,6 +192,7 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				0FA9BF9021788F4A00BA646B /* qcbor_decode_malloc_tests.c in Sources */,
 				E776E08F214AE07500E67947 /* qcbor_encode.c in Sources */,
 				0F58EB9C216A388E002FD6D1 /* qcbor_decode_malloc.c in Sources */,
 				E73B57592161CA690080D658 /* ieee754.c in Sources */,
diff --git a/inc/qcbor.h b/inc/qcbor.h
index 81f9e9c..ef020ad 100644
--- a/inc/qcbor.h
+++ b/inc/qcbor.h
@@ -1718,7 +1718,27 @@
  this function.
  */
 
-void QCBORDecode_SetUpAllocator(QCBORDecodeContext *pCtx, const QCBORStringAllocator *pAllocator);
+void QCBORDecode_SetUpAllocator(QCBORDecodeContext *pCtx, const QCBORStringAllocator *pAllocator, bool bAllStrings);
+
+
+/**
+ @brief This returns a string allocator that uses malloc
+ 
+ @return pointer to string allocator or NULL
+ 
+ Call this to get the string allocator and then configure it into
+ the decoder by calling QCBORDecode_SetUpAllocator().  If you
+ don't call this, there will be no dependency on malloc
+ in QCBOR. Some deployments of QCBOR might even exclude
+ the implementation of this function if they don't have
+ malloc() at all.
+ 
+ If you do set up this malloc-based string allocator, then
+ every string marked as allocated in a QCBORItem must
+ freed.
+ */
+
+QCBORStringAllocator *QCBORDecode_MakeMallocStringAllocator(void);
 
 
 /**
@@ -1839,6 +1859,7 @@
 
 
 
+
 /**
   Convert int64_t to smaller int's safely
  
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index ab8ce57..9a789d7 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -222,9 +222,10 @@
 /*
  Public function, see header file
  */
-void QCBORDecode_SetUpAllocator(QCBORDecodeContext *pCtx, const QCBORStringAllocator *pAllocator)
+void QCBORDecode_SetUpAllocator(QCBORDecodeContext *pCtx, const QCBORStringAllocator *pAllocator, bool bAllocAll)
 {
     pCtx->pStringAllocator = (void *)pAllocator;
+   pCtx->bStringAllocateAll = bAllocAll;
 }
 
 
@@ -438,29 +439,34 @@
 
 
 /*
- Decode text and byte strings
+ Decode text and byte strings. Call the string allocator if asked to.
  */
 inline static int DecodeBytes(QCBORStringAllocator *pAlloc, int nMajorType, uint64_t uStrLen, UsefulInputBuf *pUInBuf, QCBORItem *pDecodedItem)
 {
-    UsefulBufC Bytes = UsefulInputBuf_GetUsefulBuf(pUInBuf, uStrLen);
+   int nReturn = QCBOR_SUCCESS;
    
-   int nReturn = QCBOR_ERR_HIT_END;
-   
-   if(!UsefulBuf_IsNULLC(Bytes)) {
-      if(pAlloc) {
-         UsefulBuf NewMem = pAlloc->fAllocate(pAlloc->pAllocaterContext, NULL, uStrLen);
-         if(!UsefulBuf_IsNULL(NewMem)) {
-            pDecodedItem->val.string = UsefulBuf_Copy(NewMem, Bytes);
-         } else {
-            return QCBOR_ERR_STRING_ALLOC;
-         }
-      } else {
-         pDecodedItem->val.string = Bytes;
-      }
-      pDecodedItem->uDataType  = (nMajorType == CBOR_MAJOR_TYPE_BYTE_STRING) ? QCBOR_TYPE_BYTE_STRING : QCBOR_TYPE_TEXT_STRING;
-      nReturn = QCBOR_SUCCESS;
+   UsefulBufC Bytes = UsefulInputBuf_GetUsefulBuf(pUInBuf, uStrLen);
+   if(UsefulBuf_IsNULLC(Bytes)) {
+      // Failed to get the bytes for this string item
+      nReturn = QCBOR_ERR_HIT_END;
+      goto Done;
    }
+
+   if(pAlloc) {
+      // We are asked to use string allocator to make a copy
+      UsefulBuf NewMem = pAlloc->fAllocate(pAlloc->pAllocaterContext, NULL, uStrLen);
+      if(UsefulBuf_IsNULL(NewMem)) {
+         nReturn = QCBOR_ERR_STRING_ALLOC;
+         goto Done;
+      }
+      pDecodedItem->val.string = UsefulBuf_Copy(NewMem, Bytes);
+   } else {
+      // Normal case with no string allocator
+      pDecodedItem->val.string = Bytes;
+   }
+   pDecodedItem->uDataType  = (nMajorType == CBOR_MAJOR_TYPE_BYTE_STRING) ? QCBOR_TYPE_BYTE_STRING : QCBOR_TYPE_TEXT_STRING;
    
+Done:
    return nReturn;
 }
 
@@ -586,8 +592,8 @@
    if(nReturn)
       goto Done;
    
-   pDecodedItem->uTagBits = 0;
-   pDecodedItem->uTag     = 0;
+   pDecodedItem->uTagBits   = 0;
+   pDecodedItem->uTag       = 0;
    pDecodedItem->uDataAlloc = 0;
    
    // At this point the major type and the value are valid. We've got the type and the number that
@@ -645,7 +651,8 @@
 
 /*
  This layer deals with indefinite length strings. It pulls all the
- individual segment items together into one QCBORItem.
+ individual segment items together into one QCBORItem using the
+ string allocator.
  
  Code Reviewers: THIS FUNCTION DOES A LITTLE POINTER MATH
  */
@@ -653,6 +660,7 @@
 {
    int nReturn;
    QCBORStringAllocator *pAlloc = (QCBORStringAllocator *)me->pStringAllocator;
+   UsefulBufC FullString = NULLUsefulBufC;
    
    nReturn = GetNext_Item(&(me->InBuf), pDecodedItem, me->bStringAllocateAll ? pAlloc: NULL);
    if(nReturn) {
@@ -684,18 +692,17 @@
    const uint8_t uStringType = pDecodedItem->uDataType;
    
    // Loop getting segments of indefinite string
-   UsefulBufC FullString = NULLUsefulBufC;
    for(;;) {
       // Get item for next segment
-      QCBORItem Item;
-      // NULL passed to never alloc segments of indefinite length strings
-      nReturn = GetNext_Item(&(me->InBuf), &Item, NULL);
+      QCBORItem StringSegmentItem;
+      // NULL passed to never string alloc segments of indefinite length strings
+      nReturn = GetNext_Item(&(me->InBuf), &StringSegmentItem, NULL);
       if(nReturn) {
          break;  // Error getting the next segment
       }
       
       // See if it is a marker at end of indefinite length string
-      if(Item.uDataType == QCBOR_TYPE_BREAK) {
+      if(StringSegmentItem.uDataType == QCBOR_TYPE_BREAK) {
          // String is complete
          pDecodedItem->val.string = FullString;
          pDecodedItem->uDataAlloc = 1;
@@ -704,27 +711,27 @@
       
       // Match data type of segment to type at beginning.
       // Also catches error of other non-string types that don't belong.
-      if(Item.uDataType != uStringType) {
+      if(StringSegmentItem.uDataType != uStringType) {
          nReturn = QCBOR_ERR_INDEFINITE_STRING_SEG;
          break;
       }
       
-      // Expand the buffer so it can fit
+      // Alloc new buffer or expand previously allocated buffer so it can fit
       UsefulBuf NewMem = (*pAlloc->fAllocate)(pAlloc->pAllocaterContext,
                                               UNCONST_POINTER(FullString.ptr),
-                                              FullString.len + Item.val.string.len);
+                                              FullString.len + StringSegmentItem.val.string.len);
       if(UsefulBuf_IsNULL(NewMem)) {
          // Allocation of memory for the string failed
          nReturn = QCBOR_ERR_STRING_ALLOC;
          break;
       }
       
-      // Copy data to the end of it.
-      FullString = UsefulBuf_CopyOffset(NewMem, FullString.len, Item.val.string);
+      // Copy new string segment at the end of string so far.
+      FullString = UsefulBuf_CopyOffset(NewMem, FullString.len, StringSegmentItem.val.string);
    }
    
 Done:
-   if(pAlloc && nReturn && FullString.ptr) {
+   if(pAlloc && nReturn && !UsefulBuf_IsNULLC(FullString)) {
       // Getting item failed, clean up the allocated memory
       (pAlloc->fFree)(pAlloc->pAllocaterContext, UNCONST_POINTER(FullString.ptr));
    }
diff --git a/src/qcbor_decode_malloc.c b/src/qcbor_decode_malloc.c
index 4e405e0..9b43c75 100644
--- a/src/qcbor_decode_malloc.c
+++ b/src/qcbor_decode_malloc.c
@@ -1,22 +1,44 @@
-//
-//  qcbor_decode_malloc.c
-//  QCBOR
-//
-//  Created by Laurence Lundblade on 10/1/18.
-//  Copyright © 2018 Laurence Lundblade. All rights reserved.
-//
+/*==============================================================================
+ float_tests.c -- tests for float and conversion to/from half-precision
+ 
+ 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.
+ 
+ (This is the MIT license)
+ ==============================================================================*/
 
 #include "qcbor.h"
 #include <stdlib.h> // for realloc and free
 
 static UsefulBuf MemMallocAlloc(void *ctx, void *pOldMem, size_t uNewSize)
 {
+    (void)ctx;
     void *pNewMem = realloc(pOldMem, uNewSize);
     return (UsefulBuf){pNewMem, uNewSize};
 }
 
 static void MemMallocFree(void *ctx, void *old)
 {
+    (void)ctx;
     free(old);
 }
 
@@ -24,8 +46,9 @@
 {
     free(ctx);
 }
-
-
+/*
+ Public function. See qcbor.h
+ */
 QCBORStringAllocator *QCBORDecode_MakeMallocStringAllocator()
 {
     QCBORStringAllocator *pAllocaterContext = malloc(sizeof(QCBORStringAllocator));
@@ -33,33 +56,12 @@
         pAllocaterContext->fAllocate   = MemMallocAlloc;
         pAllocaterContext->fFree       = MemMallocFree;
         pAllocaterContext->fDestructor = MemMallocDestructor;
+        pAllocaterContext->pAllocaterContext = pAllocaterContext; // So that destructor can work.
     }
     
     return pAllocaterContext;
 }
 
 
-/*
-void QCBORDecodeMalloc_Init(QCBORDecodeContext *me, UsefulBufC EncodedCBOR, int8_t nDecodeMode)
-{
-    QCBORDecode_Init(me, EncodedCBOR, nDecodeMode);
-    
-    QCBORStringAllocator *pAllocaterContext = malloc(sizeof(QCBORStringAllocator));
-    
-    pAllocaterContext->fAllocate = MemMalloc;
-    pAllocaterContext->fFree = MemFree;
-    
-    QCBORDecode_SetUpAllocator(me, pAllocaterContext);
-}
-
-
-int QCBORDecodeMalloc_Finish(QCBORDecodeContext *me)
-{
-    const QCBORStringAllocator *pAllocator = QCBORDecode_GetAllocator(me);
-    
-    free((void *)pAllocator); // TODO: better way to cast away const here
-    return QCBORDecode_Finish(me);
-} */
-
 
 
diff --git a/test/qcbor_decode_malloc_tests.c b/test/qcbor_decode_malloc_tests.c
new file mode 100644
index 0000000..91fff98
--- /dev/null
+++ b/test/qcbor_decode_malloc_tests.c
@@ -0,0 +1,103 @@
+//
+//  qcbor_decode_malloc_tests.c
+//  QCBOR
+//
+//  Created by Laurence Lundblade on 10/18/18.
+//  Copyright © 2018 Laurence Lundblade. All rights reserved.
+//
+
+#include "qcbor_decode_malloc_tests.h"
+#include "qcbor.h"
+#include <stdlib.h>
+
+
+/*
+ {"first integer": 42,
+ "an array of two strings": ["string1", "string2"],
+ "map in a map": {
+ "bytes 1": h'78787878',
+ "bytes 2": h'79797979',
+ "another int": 98, "text 2":
+ "lies, damn lies and statistics"}
+ }
+ */
+
+static uint8_t pValidMapEncoded[] = {
+    0xa3, 0x6d, 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x65, 0x72, 0x18, 0x2a,
+    0x77, 0x61, 0x6e, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x77, 0x6f, 0x20,
+    0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x73, 0x82, 0x67, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x67,
+    0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x32, 0x6c, 0x6d, 0x61, 0x70, 0x20, 0x69, 0x6e, 0x20, 0x61, 0x20,
+    0x6d, 0x61, 0x70, 0xa4, 0x67, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x31, 0x44, 0x78, 0x78, 0x78, 0x78,
+    0x67, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x32, 0x44, 0x79, 0x79, 0x79, 0x79, 0x6b, 0x61, 0x6e, 0x6f,
+    0x74, 0x68, 0x65, 0x72, 0x20, 0x69, 0x6e, 0x74, 0x18, 0x62, 0x66, 0x74, 0x65, 0x78, 0x74, 0x20, 0x32,
+    0x78, 0x1e, 0x6c, 0x69, 0x65, 0x73, 0x2c, 0x20, 0x64, 0x61, 0x6d, 0x6e, 0x20, 0x6c, 0x69, 0x65, 0x73,
+    0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74, 0x69, 0x63, 0x73 } ;
+
+
+#define UNCONST_POINTER(ptr)    ((void *)(ptr))
+
+
+int MallocAllStringsTest()
+{
+    QCBORDecodeContext DC;
+    
+    // Next parse, save pointers to a few strings, destroy original and see all is OK.
+    MakeUsefulBufOnStack(CopyOfStorage, 160);
+    UsefulBufC CopyOf = UsefulBuf_Copy(CopyOfStorage, UsefulBuf_FromByteArrayLiteral(pValidMapEncoded));
+    
+    QCBORDecode_Init(&DC, CopyOf, QCBOR_DECODE_MODE_NORMAL);
+    QCBORStringAllocator *pAlloc = QCBORDecode_MakeMallocStringAllocator();
+    QCBORDecode_SetUpAllocator(&DC, pAlloc, true);
+
+
+    int nCBORError;
+    QCBORItem Item1, Item2, Item3, Item4;
+    if((nCBORError = QCBORDecode_GetNext(&DC, &Item1)))
+        return nCBORError;
+    if(Item1.uDataType != QCBOR_TYPE_MAP ||
+       Item1.val.uCount != 3)
+        return -1;
+    if((nCBORError = QCBORDecode_GetNext(&DC, &Item1)))
+        return nCBORError;
+    if((nCBORError = QCBORDecode_GetNext(&DC, &Item2)))
+        return nCBORError;
+    if((nCBORError = QCBORDecode_GetNext(&DC, &Item3)))
+        return nCBORError;
+    if((nCBORError = QCBORDecode_GetNext(&DC, &Item4)))
+        return nCBORError;
+    
+    UsefulBuf_Set(&CopyOfStorage, '_');
+    
+    if(Item1.uLabelType != QCBOR_TYPE_TEXT_STRING ||
+       Item1.label.string.len != 13 ||
+       Item1.uDataType != QCBOR_TYPE_INT64 ||
+       Item1.val.int64 != 42 ||
+       memcmp(Item1.label.string.ptr, "first integer", 13))
+        return -1;
+    
+    if(Item2.uLabelType != QCBOR_TYPE_TEXT_STRING ||
+       Item2.label.string.len != 23 ||
+       memcmp(Item2.label.string.ptr, "an array of two strings", 23) ||
+       Item2.uDataType != QCBOR_TYPE_ARRAY ||
+       Item2.val.uCount != 2)
+        return -1;
+    
+    if(Item3.uDataType != QCBOR_TYPE_TEXT_STRING ||
+       Item3.val.string.len != 7 ||
+       memcmp(Item3.val.string.ptr, "string1", 7))
+        return -1;
+    
+    if(Item4.uDataType != QCBOR_TYPE_TEXT_STRING ||
+       Item4.val.string.len != 7 ||
+       memcmp(Item4.val.string.ptr, "string2", 7))
+        return -1;
+    
+    (void)QCBORDecode_Finish(&DC);
+    
+    free(UNCONST_POINTER(Item1.label.string.ptr));
+    free(UNCONST_POINTER(Item2.label.string.ptr));
+    free(UNCONST_POINTER(Item3.val.string.ptr));
+    free(UNCONST_POINTER(Item4.val.string.ptr));
+
+    return 0;
+}
diff --git a/test/qcbor_decode_malloc_tests.h b/test/qcbor_decode_malloc_tests.h
new file mode 100644
index 0000000..685421c
--- /dev/null
+++ b/test/qcbor_decode_malloc_tests.h
@@ -0,0 +1,14 @@
+//
+//  qcbor_decode_malloc_tests.h
+//  QCBOR
+//
+//  Created by Laurence Lundblade on 10/18/18.
+//  Copyright © 2018 Laurence Lundblade. All rights reserved.
+//
+
+#ifndef qcbor_decode_malloc_tests_h
+#define qcbor_decode_malloc_tests_h
+
+int MallocAllStringsTest(void);
+
+#endif /* qcbor_decode_malloc_tests_h */
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index fce478d..bf48aa7 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -2257,9 +2257,6 @@
         return -1;
     }
     
-    
-    
-    
     return 0;
 }
 
diff --git a/test/qcbor_encode_tests.c b/test/qcbor_encode_tests.c
index 3636ba4..8612341 100644
--- a/test/qcbor_encode_tests.c
+++ b/test/qcbor_encode_tests.c
@@ -775,7 +775,7 @@
    if(CheckResults(Enc, pExpectedEncodedInts))
      return -1;
    
-   if(Enc.len != sizeof(pExpectedEncodedInts) || bcmp(pEncoded, pExpectedEncodedInts, Enc.len))
+   if(Enc.len != sizeof(pExpectedEncodedInts) || memcmp(pEncoded, pExpectedEncodedInts, Enc.len))
       nReturn = -1;
    
    //printencoded(pEncoded, nEncodedLen);
@@ -817,7 +817,7 @@
       nReturn = -1;
    }
    
-   if(ECBOR.len != sizeof(pExpectedEncodedSimple) || bcmp(pEncoded, pExpectedEncodedSimple, ECBOR.len))
+   if(ECBOR.len != sizeof(pExpectedEncodedSimple) || memcmp(pEncoded, pExpectedEncodedSimple, ECBOR.len))
       nReturn = -1;
    
    // printencoded(pEncoded, nEncodedLen);
@@ -874,7 +874,7 @@
       nReturn = -1;
    }
    
-   if(nEncodedLen != sizeof(pExpectedEncodedDates) || bcmp(pEncoded, pExpectedEncodedDates, nEncodedLen))
+   if(nEncodedLen != sizeof(pExpectedEncodedDates) || memcmp(pEncoded, pExpectedEncodedDates, nEncodedLen))
       nReturn = -1;
    
    //printencoded(pEncoded, nEncodedLen);
diff --git a/test/run_tests.c b/test/run_tests.c
index 8a63d78..41c70e0 100644
--- a/test/run_tests.c
+++ b/test/run_tests.c
@@ -37,6 +37,7 @@
 #include "qcbor_decode_tests.h"
 #include "qcbor_encode_tests.h"
 #include "UsefulBuf_Tests.h"
+#include "qcbor_decode_malloc_tests.h"
 
 // Used to test the test runner
 int fail_test()
@@ -112,6 +113,7 @@
 
 
 test_entry s_tests[] = {
+    TEST_ENTRY(MallocAllStringsTest),
     TEST_ENTRY(AllocAllStringsTest),
     TEST_ENTRY(IndefiniteLengthNestTest),
     TEST_ENTRY(NestedMapTestIndefLen),