Merge commit 'refs/pull/197/head' of github.com:intel/tinycbor
diff --git a/.travis.yml b/.travis.yml
index 2fd49f2..a935ac9 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -89,5 +89,4 @@
         (cd tests && make TESTARGS=-silent check -k
         TESTRUNNER=`which valgrind 2>/dev/null`)
   - make -s clean
-  - [ $BUILD_DOCS ] && ./scripts/update-docs.sh
-
+  - ! [ $BUILD_DOCS ] || ./scripts/update-docs.sh
diff --git a/examples/simplereader.c b/examples/simplereader.c
index 4752c08..0612ba4 100644
--- a/examples/simplereader.c
+++ b/examples/simplereader.c
@@ -15,6 +15,8 @@
     if (fstat(fileno(f), &st) == -1)
         return NULL;
     uint8_t *buf = malloc(st.st_size);
+    if (buf == NULL)
+        return NULL;
     *size = fread(buf, st.st_size, 1, f) == 1 ? st.st_size : 0;
     fclose(f);
     return buf;
@@ -23,13 +25,15 @@
 static void indent(int nestingLevel)
 {
     while (nestingLevel--)
-        puts("  ");
+        printf("  ");
 }
 
 static void dumpbytes(const uint8_t *buf, size_t len)
 {
+    printf("\"");
     while (len--)
-        printf("%02X ", *buf++);
+        printf("\\x%02X", *buf++);
+    printf("\"");
 }
 
 static CborError dumprecursive(CborValue *it, int nestingLevel)
@@ -85,7 +89,7 @@
             err = cbor_value_dup_text_string(it, &buf, &n, it);
             if (err)
                 return err;     // parse error
-            puts(buf);
+            printf("\"%s\"\n", buf);
             free(buf);
             continue;
         }
@@ -153,9 +157,9 @@
 
 int main(int argc, char **argv)
 {
-    if (argc == 1) {
+    if (argc != 2) {
         puts("simplereader <filename>");
-        return 0;
+        return 1;
     }
 
     size_t length;
diff --git a/src/cbor.h b/src/cbor.h
index d6360d8..313d683 100644
--- a/src/cbor.h
+++ b/src/cbor.h
@@ -242,10 +242,10 @@
 CBOR_INLINE_API CborError cbor_encode_double(CborEncoder *encoder, double value)
 { return cbor_encode_floating_point(encoder, CborDoubleType, &value); }
 
-CBOR_API CborError cbor_encoder_create_array(CborEncoder *encoder, CborEncoder *arrayEncoder, size_t length);
-CBOR_API CborError cbor_encoder_create_map(CborEncoder *encoder, CborEncoder *mapEncoder, size_t length);
-CBOR_API CborError cbor_encoder_close_container(CborEncoder *encoder, const CborEncoder *containerEncoder);
-CBOR_API CborError cbor_encoder_close_container_checked(CborEncoder *encoder, const CborEncoder *containerEncoder);
+CBOR_API CborError cbor_encoder_create_array(CborEncoder *parentEncoder, CborEncoder *arrayEncoder, size_t length);
+CBOR_API CborError cbor_encoder_create_map(CborEncoder *parentEncoder, CborEncoder *mapEncoder, size_t length);
+CBOR_API CborError cbor_encoder_close_container(CborEncoder *parentEncoder, const CborEncoder *containerEncoder);
+CBOR_API CborError cbor_encoder_close_container_checked(CborEncoder *parentEncoder, const CborEncoder *containerEncoder);
 
 CBOR_INLINE_API uint8_t *_cbor_encoder_get_buffer_pointer(const CborEncoder *encoder)
 {
diff --git a/src/cborencoder.c b/src/cborencoder.c
index fb39137..e21e83d 100644
--- a/src/cborencoder.c
+++ b/src/cborencoder.c
@@ -482,7 +482,7 @@
 }
 
 /**
- * Creates a CBOR array in the CBOR stream provided by \a encoder and
+ * Creates a CBOR array in the CBOR stream provided by \a parentEncoder and
  * initializes \a arrayEncoder so that items can be added to the array using
  * the CborEncoder functions. The array must be terminated by calling either
  * cbor_encoder_close_container() or cbor_encoder_close_container_checked()
@@ -495,13 +495,13 @@
  *
  * \sa cbor_encoder_create_map
  */
-CborError cbor_encoder_create_array(CborEncoder *encoder, CborEncoder *arrayEncoder, size_t length)
+CborError cbor_encoder_create_array(CborEncoder *parentEncoder, CborEncoder *arrayEncoder, size_t length)
 {
-    return create_container(encoder, arrayEncoder, length, ArrayType << MajorTypeShift);
+    return create_container(parentEncoder, arrayEncoder, length, ArrayType << MajorTypeShift);
 }
 
 /**
- * Creates a CBOR map in the CBOR stream provided by \a encoder and
+ * Creates a CBOR map in the CBOR stream provided by \a parentEncoder and
  * initializes \a mapEncoder so that items can be added to the map using
  * the CborEncoder functions. The map must be terminated by calling either
  * cbor_encoder_close_container() or cbor_encoder_close_container_checked()
@@ -519,11 +519,11 @@
  *
  * \sa cbor_encoder_create_array
  */
-CborError cbor_encoder_create_map(CborEncoder *encoder, CborEncoder *mapEncoder, size_t length)
+CborError cbor_encoder_create_map(CborEncoder *parentEncoder, CborEncoder *mapEncoder, size_t length)
 {
     if (length != CborIndefiniteLength && length > SIZE_MAX / 2)
         return CborErrorDataTooLarge;
-    return create_container(encoder, mapEncoder, length, MapType << MajorTypeShift);
+    return create_container(parentEncoder, mapEncoder, length, MapType << MajorTypeShift);
 }
 
 /**
@@ -538,19 +538,19 @@
  *
  * \sa cbor_encoder_create_array(), cbor_encoder_create_map()
  */
-CborError cbor_encoder_close_container(CborEncoder *encoder, const CborEncoder *containerEncoder)
+CborError cbor_encoder_close_container(CborEncoder *parentEncoder, const CborEncoder *containerEncoder)
 {
     // synchronise buffer state with that of the container
-    encoder->end = containerEncoder->end;
-    encoder->data = containerEncoder->data;
+    parentEncoder->end = containerEncoder->end;
+    parentEncoder->data = containerEncoder->data;
 
     if (containerEncoder->flags & CborIteratorFlag_UnknownLength)
-        return append_byte_to_buffer(encoder, BreakByte);
+        return append_byte_to_buffer(parentEncoder, BreakByte);
 
     if (containerEncoder->remaining != 1)
         return containerEncoder->remaining == 0 ? CborErrorTooManyItems : CborErrorTooFewItems;
 
-    if (!encoder->end)
+    if (!parentEncoder->end)
         return CborErrorOutOfMemory;    /* keep the state */
 
     return CborNoError;
diff --git a/src/cbortojson.c b/src/cbortojson.c
index a0f3262..4b11d31 100644
--- a/src/cbortojson.c
+++ b/src/cbortojson.c
@@ -179,6 +179,10 @@
 
     /* a Base16 (hex) output is twice as big as our buffer */
     buffer = (uint8_t *)malloc(n * 2 + 1);
+    if (buffer == NULL)
+        /* out of memory */
+        return CborErrorOutOfMemory;
+
     *result = (char *)buffer;
 
     /* let cbor_value_copy_byte_string know we have an extra byte for the terminating NUL */
@@ -204,7 +208,12 @@
 
     /* a Base64 output (untruncated) has 4 bytes for every 3 in the input */
     size_t len = (n + 5) / 3 * 4;
-    out = buffer = (uint8_t *)malloc(len + 1);
+    buffer = (uint8_t *)malloc(len + 1);
+    if (buffer == NULL)
+        /* out of memory */
+        return CborErrorOutOfMemory;
+
+    out = buffer;
     *result = (char *)buffer;
 
     /* we read our byte string at the tail end of the buffer