Merge remote-tracking branch 'refs/remotes/cabo/master' into windows

Conflicts:
	include/cn-cbor/cn-cbor.h
	src/cn-cbor.c
	src/cn-get.c
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..f1c9628
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,14 @@
+language: c
+compiler:
+- clang
+- gcc
+sudo: false
+before_install:
+- wget http://www.cmake.org/files/v3.3/cmake-3.3.1-Linux-x86_64.tar.gz  -O /tmp/cmake.tar.gz
+- tar xzf /tmp/cmake.tar.gz
+- export PATH=$PWD/cmake-3.3.1-Linux-x86_64/bin/:$PATH
+script:
+- "./build.sh all test"
+notifications:
+  slack:
+    secure: WdgYxQrnFR5eu/eKygPuLjlFsuZxD9m2PLRWTLT85aj+18Gp2ooPjnI9UFdb1xY87+4InhWk6PvQU35j4bG0etPQtX+0H4T4Zdk/aD6KxgJBHIYGqtfZUMmdFfVpUH9cCPx99Jjw81mhKrxM+6rXiZdiWXuNhvbJOApRT6uxE2k=
diff --git a/README.md b/README.md
index 9b57776..5820858 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,5 @@
+[![Build Status](https://travis-ci.org/cabo/cn-cbor.png?branch=master)](https://travis-ci.org/cabo/cn-cbor)
+
 # cn-cbor: A constrained node implementation of CBOR in C
 
 This is a constrained node implementation of [CBOR](http://cbor.io) in
diff --git a/build.sh b/build.sh
index a07f37f..69dd2e9 100755
--- a/build.sh
+++ b/build.sh
@@ -1,3 +1,4 @@
+#!/bin/sh
 if [ ! -d "build" ]; then
     mkdir build
 fi
diff --git a/include/cn-cbor/cn-cbor.h b/include/cn-cbor/cn-cbor.h
index 568b57c..a0f9e4e 100644
--- a/include/cn-cbor/cn-cbor.h
+++ b/include/cn-cbor/cn-cbor.h
@@ -97,7 +97,9 @@
   /** Data associated with the value; different branches of the union are
       used depending on the `type` field. */
   union {
-    /** CN_CBOR_BYTES, CN_CBOR_TEXT */
+    /** CN_CBOR_BYTES */
+    const uint8_t* bytes;
+    /** CN_CBOR_TEXT */
     const char* str;
     /** CN_CBOR_INT */
 #ifdef _MSC_VER
@@ -284,8 +286,10 @@
 
 /**
  * Free the given CBOR structure.
+ * You MUST NOT try to free a cn_cbor structure with a parent (i.e., one
+ * that is not a root in the tree).
  *
- * @param[in]  cb           The CBOR value to free
+ * @param[in]  cb           The CBOR value to free.  May be NULL, or a root object.
  * @param[in]  CBOR_CONTEXT Allocation context (only if USE_CBOR_CONTEXT is defined)
  */
 MYLIB_EXPORT
diff --git a/src/cn-cbor.c b/src/cn-cbor.c
index 3be52b3..61416f1 100644
--- a/src/cn-cbor.c
+++ b/src/cn-cbor.c
@@ -27,8 +27,9 @@
 #define CN_CBOR_FAIL(code) do { pb->err = code;  goto fail; } while(0)
 
 MYLIB_EXPORT
-void cn_cbor_free(const cn_cbor* cb CBOR_CONTEXT) {
+void cn_cbor_free(cn_cbor* cb CBOR_CONTEXT) {
   cn_cbor* p = (cn_cbor*) cb;
+  assert(!p || !p->parent);
   while (p) {
     cn_cbor* p1;
     while ((p1 = p->first_child)) { /* go down */
diff --git a/test/cbor_test.c b/test/cbor_test.c
index 8c53a93..3266631 100644
--- a/test/cbor_test.c
+++ b/test/cbor_test.c
@@ -127,7 +127,7 @@
         "9f009f00ff00ff",         // [_ 0, [_ 0], 0]
         "bf61610161629f0203ffff", // {_ "a": 1, "b": [_ 2, 3]}
     };
-    const cn_cbor *cb;
+    cn_cbor *cb;
     buffer b;
     size_t i;
     unsigned char encoded[1024];
@@ -175,7 +175,7 @@
       "fb3e78000000000000", "fa33c00000", //  8.940696716308594e-08
       "fb3e80000000000000", "f90002",   // 1.1920928955078125e-07
     };
-    const cn_cbor *cb;
+    cn_cbor *cb;
     buffer b, b2;
     size_t i;
     unsigned char encoded[1024];
@@ -237,7 +237,7 @@
         {"1c", CN_CBOR_ERR_RESERVED_AI},
         {"7f4100", CN_CBOR_ERR_WRONG_NESTING_IN_INDEF_STRING},
     };
-    const cn_cbor *cb;
+    cn_cbor *cb;
     buffer b;
     size_t i;
     uint8_t buf[10];
@@ -269,7 +269,7 @@
         "f9fc00", // -Inf
         "f97c00", // Inf
     };
-    const cn_cbor *cb;
+    cn_cbor *cb;
     buffer b;
     size_t i;
     unsigned char encoded[1024];
@@ -292,8 +292,8 @@
 CTEST(cbor, getset)
 {
     buffer b;
-    const cn_cbor *cb;
-    const cn_cbor *val;
+    cn_cbor *cb;
+    cn_cbor *val;
     cn_cbor_errback err;
 
     ASSERT_TRUE(parse_hex("a40000436363630262626201616100", &b));
diff --git a/test/test.c b/test/test.c
index 263f9fe..d24992f 100644
--- a/test/test.c
+++ b/test/test.c
@@ -115,7 +115,7 @@
   char *bufend;
   unsigned char *s = load_file("cases.cbor", &end);
   printf("%zd\n", end-s);
-  const cn_cbor *cb = cn_cbor_decode(s, end-s CBOR_CONTEXT_PARAM, 0);
+  cn_cbor *cb = cn_cbor_decode(s, end-s CBOR_CONTEXT_PARAM, 0);
   if (cb) {
     dump(cb, buf, &bufend, 0);
     *bufend = 0;