Add explicit casts and fix return type mismatches
diff --git a/src/bplist.c b/src/bplist.c
index 897b90f..953c2c7 100644
--- a/src/bplist.c
+++ b/src/bplist.c
@@ -47,7 +47,8 @@
 #define BPLIST_VERSION          ((uint8_t*)"00")
 #define BPLIST_VERSION_SIZE     2
 
-typedef struct __attribute__((packed)) {
+#pragma pack(push,1)
+typedef struct {
     uint8_t unused[6];
     uint8_t offset_size;
     uint8_t ref_size;
@@ -55,6 +56,7 @@
     uint64_t root_object_index;
     uint64_t offset_table_offset;
 } bplist_trailer_t;
+#pragma pack(pop)
 
 enum
 {
@@ -384,7 +386,7 @@
 	outbuf[p] = 0;
 
 	/* reduce the size to the actual size */
-	outbuf_new = realloc(outbuf, p+1);
+	outbuf_new = (char*)realloc(outbuf, p+1);
 	if (outbuf_new) {
 		outbuf = outbuf_new;
 	}
@@ -498,8 +500,8 @@
             return NULL;
         }
 
-        node_attach(node, key);
-        node_attach(node, val);
+        node_attach((node_t)node, (node_t)key);
+        node_attach((node_t)node, (node_t)val);
     }
 
     return node;
@@ -543,7 +545,7 @@
             return NULL;
         }
 
-        node_attach(node, val);
+        node_attach((node_t)node, (node_t)val);
     }
 
     return node;
@@ -1229,7 +1231,7 @@
     //serialize plist
     ser_s.objects = objects;
     ser_s.ref_table = ref_table;
-    serialize_plist(plist, &ser_s);
+    serialize_plist((node_t)plist, &ser_s);
 
     //now stream to output buffer
     offset_size = 0;			//unknown yet
@@ -1243,7 +1245,7 @@
     uint64_t req = 0;
     for (i = 0; i < num_objects; i++)
     {
-        node_t node = ptr_array_index(objects, i);
+        node_t node = (node_t)ptr_array_index(objects, i);
         plist_data_t data = plist_get_data(node);
         uint64_t size;
         uint8_t bsize;
@@ -1382,10 +1384,10 @@
             write_data(bplist_buff, data->buff, data->length);
             break;
         case PLIST_ARRAY:
-            write_array(bplist_buff, ptr_array_index(objects, i), ref_table, ref_size);
+            write_array(bplist_buff, (node_t)ptr_array_index(objects, i), ref_table, ref_size);
             break;
         case PLIST_DICT:
-            write_dict(bplist_buff, ptr_array_index(objects, i), ref_table, ref_size);
+            write_dict(bplist_buff, (node_t)ptr_array_index(objects, i), ref_table, ref_size);
             break;
         case PLIST_DATE:
             write_date(bplist_buff, data->realval);
@@ -1423,7 +1425,7 @@
     byte_array_append(bplist_buff, &trailer, sizeof(bplist_trailer_t));
 
     //set output buffer and size
-    *plist_bin = bplist_buff->data;
+    *plist_bin = (char*)bplist_buff->data;
     *length = bplist_buff->len;
 
     bplist_buff->data = NULL; // make sure we don't free the output buffer
diff --git a/src/hashtable.c b/src/hashtable.c
index dd6dbfc..86dae82 100644
--- a/src/hashtable.c
+++ b/src/hashtable.c
@@ -47,7 +47,7 @@
 					ht->free_func(e->value);
 				}
 				hashentry_t* old = e;
-				e = e->next;
+				e = (hashentry_t*)e->next;
 				free(old);
 			}
 		}
@@ -71,7 +71,7 @@
 			e->value = value;
 			return;
 		}
-		e = e->next;
+		e = (hashentry_t*)e->next;
 	}
 
 	// if we get here, the element is not yet in the list.
@@ -103,7 +103,7 @@
 		if (ht->compare_func(e->key, key)) {
 			return e->value;
 		}
-		e = e->next;
+		e = (hashentry_t*)e->next;
 	}
 	return NULL;
 }
@@ -124,7 +124,7 @@
 			// found element, remove it from the list
 			hashentry_t* old = e;
 			if (e == ht->entries[idx0]) {
-				ht->entries[idx0] = e->next;
+				ht->entries[idx0] = (hashentry_t*)e->next;
 			} else {
 				last->next = e->next;
 			}
@@ -135,6 +135,6 @@
 			return;
 		}
 		last = e;
-		e = e->next;
+		e = (hashentry_t*)e->next;
 	}
 }
diff --git a/src/jplist.c b/src/jplist.c
index f6c96ca..782d2b3 100644
--- a/src/jplist.c
+++ b/src/jplist.c
@@ -110,7 +110,7 @@
     return len;
 }
 
-static int node_to_json(node_t node, bytearray_t **outbuf, uint32_t depth, int prettify)
+static plist_err_t node_to_json(node_t node, bytearray_t **outbuf, uint32_t depth, int prettify)
 {
     plist_data_t node_data = NULL;
 
@@ -206,7 +206,7 @@
                     str_buf_append(*outbuf, "  ", 2);
                 }
             }
-            int res = node_to_json(ch, outbuf, depth+1, prettify);
+            plist_err_t res = node_to_json(ch, outbuf, depth+1, prettify);
             if (res < 0) {
                 return res;
             }
@@ -234,7 +234,7 @@
                     str_buf_append(*outbuf, "  ", 2);
                 }
             }
-            int res = node_to_json(ch, outbuf, depth+1, prettify);
+            plist_err_t res = node_to_json(ch, outbuf, depth+1, prettify);
             if (res < 0) {
                 return res;
             }
@@ -311,7 +311,7 @@
     return n;
 }
 
-static int node_estimate_size(node_t node, uint64_t *size, uint32_t depth, int prettify)
+static plist_err_t node_estimate_size(node_t node, uint64_t *size, uint32_t depth, int prettify)
 {
     plist_data_t data;
     if (!node) {
@@ -322,7 +322,7 @@
         node_t ch;
         unsigned int n_children = node_n_children(node);
         for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) {
-            int res = node_estimate_size(ch, size, depth + 1, prettify);
+            plist_err_t res = node_estimate_size(ch, size, depth + 1, prettify);
             if (res < 0) {
                 return res;
             }
@@ -401,7 +401,7 @@
 plist_err_t plist_to_json(plist_t plist, char **plist_json, uint32_t* length, int prettify)
 {
     uint64_t size = 0;
-    int res;
+    plist_err_t res;
 
     if (!plist || !plist_json || !length) {
         return PLIST_ERR_INVALID_ARG;
@@ -412,7 +412,7 @@
         return PLIST_ERR_FORMAT;
     }
 
-    res = node_estimate_size(plist, &size, 0, prettify);
+    res = node_estimate_size((node_t)plist, &size, 0, prettify);
     if (res < 0) {
         return res;
     }
@@ -423,7 +423,7 @@
         return PLIST_ERR_NO_MEM;
     }
 
-    res = node_to_json(plist, &outbuf, 0, prettify);
+    res = node_to_json((node_t)plist, &outbuf, 0, prettify);
     if (res < 0) {
         str_buf_free(outbuf);
         *plist_json = NULL;
@@ -436,7 +436,7 @@
 
     str_buf_append(outbuf, "\0", 1);
 
-    *plist_json = outbuf->data;
+    *plist_json = (char*)outbuf->data;
     *length = outbuf->len - 1;
 
     outbuf->data = NULL;
@@ -800,7 +800,7 @@
     jsmntok_t *tokens = NULL;
 
     do {
-        jsmntok_t* newtokens = realloc(tokens, sizeof(jsmntok_t)*maxtoks);
+        jsmntok_t* newtokens = (jsmntok_t*)realloc(tokens, sizeof(jsmntok_t)*maxtoks);
         if (!newtokens) {
             PLIST_JSON_ERR("%s: Out of memory\n", __func__);
             return PLIST_ERR_NO_MEM;
diff --git a/src/oplist.c b/src/oplist.c
index 7597b3c..6ab6603 100644
--- a/src/oplist.c
+++ b/src/oplist.c
@@ -139,7 +139,7 @@
     return 0;
 }
 
-static int node_to_openstep(node_t node, bytearray_t **outbuf, uint32_t depth, int prettify)
+static plist_err_t node_to_openstep(node_t node, bytearray_t **outbuf, uint32_t depth, int prettify)
 {
     plist_data_t node_data = NULL;
 
@@ -230,7 +230,7 @@
                     str_buf_append(*outbuf, "  ", 2);
                 }
             }
-            int res = node_to_openstep(ch, outbuf, depth+1, prettify);
+            plist_err_t res = node_to_openstep(ch, outbuf, depth+1, prettify);
             if (res < 0) {
                 return res;
             }
@@ -258,7 +258,7 @@
                     str_buf_append(*outbuf, "  ", 2);
                 }
             }
-            int res = node_to_openstep(ch, outbuf, depth+1, prettify);
+            plist_err_t res = node_to_openstep(ch, outbuf, depth+1, prettify);
             if (res < 0) {
                 return res;
             }
@@ -355,7 +355,7 @@
     return n;
 }
 
-static int node_estimate_size(node_t node, uint64_t *size, uint32_t depth, int prettify)
+static plist_err_t node_estimate_size(node_t node, uint64_t *size, uint32_t depth, int prettify)
 {
     plist_data_t data;
     if (!node) {
@@ -366,7 +366,7 @@
         node_t ch;
         unsigned int n_children = node_n_children(node);
         for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) {
-            int res = node_estimate_size(ch, size, depth + 1, prettify);
+            plist_err_t res = node_estimate_size(ch, size, depth + 1, prettify);
             if (res < 0) {
                 return res;
             }
@@ -445,13 +445,13 @@
 plist_err_t plist_to_openstep(plist_t plist, char **openstep, uint32_t* length, int prettify)
 {
     uint64_t size = 0;
-    int res;
+    plist_err_t res;
 
     if (!plist || !openstep || !length) {
         return PLIST_ERR_INVALID_ARG;
     }
 
-    res = node_estimate_size(plist, &size, 0, prettify);
+    res = node_estimate_size((node_t)plist, &size, 0, prettify);
     if (res < 0) {
         return res;
     }
@@ -462,7 +462,7 @@
         return PLIST_ERR_NO_MEM;
     }
 
-    res = node_to_openstep(plist, &outbuf, 0, prettify);
+    res = node_to_openstep((node_t)plist, &outbuf, 0, prettify);
     if (res < 0) {
         str_buf_free(outbuf);
         *openstep = NULL;
@@ -475,7 +475,7 @@
 
     str_buf_append(outbuf, "\0", 1);
 
-    *openstep = outbuf->data;
+    *openstep = (char*)outbuf->data;
     *length = outbuf->len - 1;
 
     outbuf->data = NULL;
@@ -532,7 +532,7 @@
 
 #define HEX_DIGIT(x) ((x <= '9') ? (x - '0') : ((x <= 'F') ? (x - 'A' + 10) : (x - 'a' + 10)))
 
-static int node_from_openstep(parse_ctx ctx, plist_t *plist);
+static plist_err_t node_from_openstep(parse_ctx ctx, plist_t *plist);
 
 static void parse_dict_data(parse_ctx ctx, plist_t dict)
 {
@@ -603,7 +603,7 @@
     plist_free(val);
 }
 
-static int node_from_openstep(parse_ctx ctx, plist_t *plist)
+static plist_err_t node_from_openstep(parse_ctx ctx, plist_t *plist)
 {
     plist_t subnode = NULL;
     const char *p = NULL;
@@ -746,7 +746,7 @@
                 goto err_out;
             }
             ctx->pos++;
-            data->buff = bytes->data;
+            data->buff = (uint8_t*)bytes->data;
             data->length = bytes->len;
             bytes->data = NULL;
             byte_array_free(bytes);
@@ -781,7 +781,7 @@
             }
             size_t slen = ctx->pos - p;
             ctx->pos++; // skip the closing quote
-            char* strbuf = malloc(slen+1);
+            char* strbuf = (char*)malloc(slen+1);
             if (num_escapes > 0) {
                 size_t i = 0;
                 size_t o = 0;
@@ -907,7 +907,7 @@
 
     struct _parse_ctx ctx = { plist_ostep, plist_ostep, plist_ostep + length, 0 , 0 };
 
-    int err = node_from_openstep(&ctx, plist);
+    plist_err_t err = node_from_openstep(&ctx, plist);
     if (err == 0) {
         if (!*plist) {
             /* whitespace only file is considered an empty dictionary */
diff --git a/src/out-default.c b/src/out-default.c
index 3ee9b3a..266070b 100644
--- a/src/out-default.c
+++ b/src/out-default.c
@@ -65,7 +65,7 @@
     return len;
 }
 
-static int node_to_string(node_t node, bytearray_t **outbuf, uint32_t depth, uint32_t indent, int partial_data)
+static plist_err_t node_to_string(node_t node, bytearray_t **outbuf, uint32_t depth, uint32_t indent, int partial_data)
 {
     plist_data_t node_data = NULL;
 
@@ -159,7 +159,7 @@
             for (i = 0; i <= depth+indent; i++) {
                 str_buf_append(*outbuf, "  ", 2);
             }
-            int res = node_to_string(ch, outbuf, depth+1, indent, partial_data);
+            plist_err_t res = node_to_string(ch, outbuf, depth+1, indent, partial_data);
             if (res < 0) {
                 return res;
             }
@@ -187,7 +187,7 @@
                     str_buf_append(*outbuf, "  ", 2);
                 }
             }
-            int res = node_to_string(ch, outbuf, depth+1, indent, partial_data);
+            plist_err_t res = node_to_string(ch, outbuf, depth+1, indent, partial_data);
             if (res < 0) {
                 return res;
             }
@@ -310,7 +310,7 @@
     return n;
 }
 
-static int node_estimate_size(node_t node, uint64_t *size, uint32_t depth, uint32_t indent, int partial_data)
+static plist_err_t node_estimate_size(node_t node, uint64_t *size, uint32_t depth, uint32_t indent, int partial_data)
 {
     plist_data_t data;
     if (!node) {
@@ -321,7 +321,7 @@
         node_t ch;
         unsigned int n_children = node_n_children(node);
         for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) {
-            int res = node_estimate_size(ch, size, depth + 1, indent, partial_data);
+            plist_err_t res = node_estimate_size(ch, size, depth + 1, indent, partial_data);
             if (res < 0) {
                 return res;
             }
@@ -411,7 +411,7 @@
     for (i = 0; i < indent; i++) {
         str_buf_append(outbuf, "  ", 2);
     }
-    int res = node_to_string(plist, &outbuf, 0, indent, options & PLIST_OPT_PARTIAL_DATA);
+    plist_err_t res = node_to_string((node_t)plist, &outbuf, 0, indent, options & PLIST_OPT_PARTIAL_DATA);
     if (res < 0) {
         return res;
     }
@@ -424,7 +424,7 @@
 plist_err_t plist_write_to_string_default(plist_t plist, char **output, uint32_t* length, plist_write_options_t options)
 {
     uint64_t size = 0;
-    int res;
+    plist_err_t res;
 
     if (!plist || !output || !length) {
         return PLIST_ERR_INVALID_ARG;
@@ -435,7 +435,7 @@
         indent = (options >> 24) & 0xFF;
     }
 
-    res = node_estimate_size(plist, &size, 0, indent, options & PLIST_OPT_PARTIAL_DATA);
+    res = node_estimate_size((node_t)plist, &size, 0, indent, options & PLIST_OPT_PARTIAL_DATA);
     if (res < 0) {
         return res;
     }
@@ -457,7 +457,7 @@
     }
     str_buf_append(outbuf, "\0", 1);
 
-    *output = outbuf->data;
+    *output = (char*)outbuf->data;
     *length = outbuf->len - 1;
 
     outbuf->data = NULL;
@@ -479,7 +479,7 @@
         return PLIST_ERR_NO_MEM;
     }
 
-    int res = _plist_write_to_strbuf(plist, outbuf, options);
+    plist_err_t res = _plist_write_to_strbuf(plist, outbuf, options);
     if (res < 0) {
         str_buf_free(outbuf);
         return res;
diff --git a/src/out-limd.c b/src/out-limd.c
index 433ae06..7d861f8 100644
--- a/src/out-limd.c
+++ b/src/out-limd.c
@@ -67,7 +67,7 @@
     return len;
 }
 
-static int node_to_string(node_t node, bytearray_t **outbuf, uint32_t depth, uint32_t indent)
+static plist_err_t node_to_string(node_t node, bytearray_t **outbuf, uint32_t depth, uint32_t indent)
 {
     plist_data_t node_data = NULL;
 
@@ -154,7 +154,7 @@
             }
             size_t sl = sprintf(buf, "%u: ", cnt);
             str_buf_append(*outbuf, buf, sl);
-            int res = node_to_string(ch, outbuf, depth+1, indent);
+            plist_err_t res = node_to_string(ch, outbuf, depth+1, indent);
             if (res < 0) {
                 return res;
             }
@@ -171,7 +171,7 @@
                     str_buf_append(*outbuf, " ", 1);
                 }
             }
-            int res = node_to_string(ch, outbuf, depth+1, indent);
+            plist_err_t res = node_to_string(ch, outbuf, depth+1, indent);
             if (res < 0) {
                 return res;
             }
@@ -278,7 +278,7 @@
     return n;
 }
 
-static int node_estimate_size(node_t node, uint64_t *size, uint32_t depth, uint32_t indent)
+static plist_err_t node_estimate_size(node_t node, uint64_t *size, uint32_t depth, uint32_t indent)
 {
     plist_data_t data;
     if (!node) {
@@ -289,7 +289,7 @@
         node_t ch;
         unsigned int n_children = node_n_children(node);
         for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) {
-            int res = node_estimate_size(ch, size, depth + 1, indent);
+            plist_err_t res = node_estimate_size(ch, size, depth + 1, indent);
             if (res < 0) {
                 return res;
             }
@@ -369,7 +369,7 @@
     for (i = 0; i < indent; i++) {
         str_buf_append(outbuf, " ", 1);
     }
-    int res = node_to_string(plist, &outbuf, 0, indent);
+    plist_err_t res = node_to_string((node_t)plist, &outbuf, 0, indent);
     if (res < 0) {
         return res;
     }
@@ -382,7 +382,7 @@
 plist_err_t plist_write_to_string_limd(plist_t plist, char **output, uint32_t* length, plist_write_options_t options)
 {
     uint64_t size = 0;
-    int res;
+    plist_err_t res;
 
     if (!plist || !output || !length) {
         return PLIST_ERR_INVALID_ARG;
@@ -393,7 +393,7 @@
         indent = (options >> 24) & 0xFF;
     }
 
-    res = node_estimate_size(plist, &size, 0, indent);
+    res = node_estimate_size((node_t)plist, &size, 0, indent);
     if (res < 0) {
         return res;
     }
@@ -415,7 +415,7 @@
     }
     str_buf_append(outbuf, "\0", 1);
 
-    *output = outbuf->data;
+    *output = (char*)outbuf->data;
     *length = outbuf->len - 1;
 
     outbuf->data = NULL;
@@ -437,7 +437,7 @@
         return PLIST_ERR_NO_MEM;
     }
 
-    int res = _plist_write_to_strbuf(plist, outbuf, options);
+    plist_err_t res = _plist_write_to_strbuf(plist, outbuf, options);
     if (res < 0) {
         str_buf_free(outbuf);
         return res;
diff --git a/src/out-plutil.c b/src/out-plutil.c
index ed71d8f..d85f22c 100644
--- a/src/out-plutil.c
+++ b/src/out-plutil.c
@@ -65,7 +65,7 @@
     return len;
 }
 
-static int node_to_string(node_t node, bytearray_t **outbuf, uint32_t depth)
+static plist_err_t node_to_string(node_t node, bytearray_t **outbuf, uint32_t depth)
 {
     plist_data_t node_data = NULL;
 
@@ -159,7 +159,7 @@
             char indexbuf[16];
             int l = sprintf(indexbuf, "%u => ", cnt);
             str_buf_append(*outbuf, indexbuf, l);
-            int res = node_to_string(ch, outbuf, depth+1);
+            plist_err_t res = node_to_string(ch, outbuf, depth+1);
             if (res < 0) {
                 return res;
             }
@@ -184,7 +184,7 @@
                     str_buf_append(*outbuf, "  ", 2);
                 }
             }
-            int res = node_to_string(ch, outbuf, depth+1);
+            plist_err_t res = node_to_string(ch, outbuf, depth+1);
             if (res < 0) {
                 return res;
             }
@@ -304,7 +304,7 @@
     return n;
 }
 
-static int node_estimate_size(node_t node, uint64_t *size, uint32_t depth)
+static plist_err_t node_estimate_size(node_t node, uint64_t *size, uint32_t depth)
 {
     plist_data_t data;
     if (!node) {
@@ -315,7 +315,7 @@
         node_t ch;
         unsigned int n_children = node_n_children(node);
         for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) {
-            int res = node_estimate_size(ch, size, depth + 1);
+            plist_err_t res = node_estimate_size(ch, size, depth + 1);
             if (res < 0) {
                 return res;
             }
@@ -390,7 +390,7 @@
 
 static plist_err_t _plist_write_to_strbuf(plist_t plist, strbuf_t *outbuf, plist_write_options_t options)
 {
-    int res = node_to_string(plist, &outbuf, 0);
+    plist_err_t res = node_to_string((node_t)plist, &outbuf, 0);
     if (res < 0) {
         return res;
     }
@@ -403,13 +403,13 @@
 plist_err_t plist_write_to_string_plutil(plist_t plist, char **output, uint32_t* length, plist_write_options_t options)
 {
     uint64_t size = 0;
-    int res;
+    plist_err_t res;
 
     if (!plist || !output || !length) {
         return PLIST_ERR_INVALID_ARG;
     }
 
-    res = node_estimate_size(plist, &size, 0);
+    res = node_estimate_size((node_t)plist, &size, 0);
     if (res < 0) {
         return res;
     }
@@ -431,7 +431,7 @@
     }
     str_buf_append(outbuf, "\0", 1);
 
-    *output = outbuf->data;
+    *output = (char*)outbuf->data;
     *length = outbuf->len - 1;
 
     outbuf->data = NULL;
@@ -453,7 +453,7 @@
         return PLIST_ERR_NO_MEM;
     }
 
-    int res = _plist_write_to_strbuf(plist, outbuf, options);
+    plist_err_t res = _plist_write_to_strbuf(plist, outbuf, options);
     if (res < 0) {
         str_buf_free(outbuf);
         return res;
diff --git a/src/plist.c b/src/plist.c
index ccb7359..d78f748 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -47,6 +47,10 @@
 #include <hashtable.h>
 #include <ptrarray.h>
 
+#ifdef _MSC_VER
+typedef SSIZE_T ssize_t;
+#endif
+
 extern void plist_xml_init(void);
 extern void plist_xml_deinit(void);
 extern void plist_bin_init(void);
@@ -199,7 +203,7 @@
 
 plist_err_t plist_from_memory(const char *plist_data, uint32_t length, plist_t *plist, plist_format_t *format)
 {
-    int res = -1;
+    plist_err_t res = PLIST_ERR_UNKNOWN;
     if (!plist) {
         return PLIST_ERR_INVALID_ARG;
     }
@@ -284,7 +288,7 @@
     if (total == 0) {
         return PLIST_ERR_PARSE;
     }
-    char *buf = malloc(total);
+    char *buf = (char*)malloc(total);
     if (!buf) {
         fclose(f);
         return PLIST_ERR_NO_MEM;
@@ -316,7 +320,7 @@
 {
     if (!node)
         return NULL;
-    return ((node_t)node)->data;
+    return (plist_data_t)((node_t)node)->data;
 }
 
 plist_data_t plist_new_plist_data(void)
@@ -364,10 +368,10 @@
             free(data->buff);
             break;
         case PLIST_ARRAY:
-            ptr_array_free(data->hashtable);
+            ptr_array_free((ptrarray_t*)data->hashtable);
             break;
         case PLIST_DICT:
-            hash_table_destroy(data->hashtable);
+            hash_table_destroy((hashtable_t*)data->hashtable);
             break;
         default:
             break;
@@ -506,7 +510,7 @@
 {
     if (plist)
     {
-        plist_free_node(plist);
+        plist_free_node((node_t)plist);
     }
 }
 
@@ -565,7 +569,7 @@
         /* copy child node */
         plist_t newch = plist_copy_node(ch);
         /* attach to new parent node */
-        node_attach(newnode, newch);
+        node_attach((node_t)newnode, (node_t)newch);
         /* if needed, add child node to lookup table of parent node */
         switch (node_type) {
             case PLIST_ARRAY:
@@ -588,7 +592,7 @@
 
 plist_t plist_copy(plist_t node)
 {
-    return node ? plist_copy_node(node) : NULL;
+    return node ? plist_copy_node((node_t)node) : NULL;
 }
 
 uint32_t plist_array_get_size(plist_t node)
@@ -596,7 +600,7 @@
     uint32_t ret = 0;
     if (node && PLIST_ARRAY == plist_get_node_type(node))
     {
-        ret = node_n_children(node);
+        ret = node_n_children((node_t)node);
     }
     return ret;
 }
@@ -606,11 +610,11 @@
     plist_t ret = NULL;
     if (node && PLIST_ARRAY == plist_get_node_type(node) && n < INT_MAX)
     {
-        ptrarray_t *pa = ((plist_data_t)((node_t)node)->data)->hashtable;
+        ptrarray_t *pa = (ptrarray_t*)((plist_data_t)((node_t)node)->data)->hashtable;
         if (pa) {
             ret = (plist_t)ptr_array_index(pa, n);
         } else {
-            ret = (plist_t)node_nth_child(node, n);
+            ret = (plist_t)node_nth_child((node_t)node, n);
         }
     }
     return ret;
@@ -621,14 +625,14 @@
     plist_t father = plist_get_parent(node);
     if (PLIST_ARRAY == plist_get_node_type(father))
     {
-        return node_child_position(father, node);
+        return node_child_position((node_t)father, (node_t)node);
     }
     return UINT_MAX;
 }
 
 static void _plist_array_post_insert(plist_t node, plist_t item, long n)
 {
-    ptrarray_t *pa = ((plist_data_t)((node_t)node)->data)->hashtable;
+    ptrarray_t *pa = (ptrarray_t*)((plist_data_t)((node_t)node)->data)->hashtable;
     if (pa) {
         /* store pointer to item in array */
         ptr_array_insert(pa, item, n);
@@ -637,9 +641,9 @@
             /* make new lookup array */
             pa = ptr_array_new(128);
             plist_t current = NULL;
-            for (current = (plist_t)node_first_child(node);
+            for (current = (plist_t)node_first_child((node_t)node);
                  pa && current;
-                 current = (plist_t)node_next_sibling(current))
+                 current = (plist_t)node_next_sibling((node_t)current))
             {
                 ptr_array_add(pa, current);
             }
@@ -655,13 +659,13 @@
         plist_t old_item = plist_array_get_item(node, n);
         if (old_item)
         {
-            int idx = plist_free_node(old_item);
+            int idx = plist_free_node((node_t)old_item);
             assert(idx >= 0);
             if (idx < 0) {
                 return;
             }
-            node_insert(node, idx, item);
-            ptrarray_t* pa = ((plist_data_t)((node_t)node)->data)->hashtable;
+            node_insert((node_t)node, idx, (node_t)item);
+            ptrarray_t* pa = (ptrarray_t*)((plist_data_t)((node_t)node)->data)->hashtable;
             if (pa) {
                 ptr_array_set(pa, item, idx);
             }
@@ -673,7 +677,7 @@
 {
     if (node && PLIST_ARRAY == plist_get_node_type(node))
     {
-        node_attach(node, item);
+        node_attach((node_t)node, (node_t)item);
         _plist_array_post_insert(node, item, -1);
     }
 }
@@ -682,7 +686,7 @@
 {
     if (node && PLIST_ARRAY == plist_get_node_type(node) && n < INT_MAX)
     {
-        node_insert(node, n, item);
+        node_insert((node_t)node, n, (node_t)item);
         _plist_array_post_insert(node, item, (long)n);
     }
 }
@@ -694,7 +698,7 @@
         plist_t old_item = plist_array_get_item(node, n);
         if (old_item)
         {
-            ptrarray_t* pa = ((plist_data_t)((node_t)node)->data)->hashtable;
+            ptrarray_t* pa = (ptrarray_t*)((plist_data_t)((node_t)node)->data)->hashtable;
             if (pa) {
                 ptr_array_remove(pa, n);
             }
@@ -708,9 +712,9 @@
     plist_t father = plist_get_parent(node);
     if (PLIST_ARRAY == plist_get_node_type(father))
     {
-        int n = node_child_position(father, node);
+        int n = node_child_position((node_t)father, (node_t)node);
         if (n < 0) return;
-        ptrarray_t* pa = ((plist_data_t)((node_t)father)->data)->hashtable;
+        ptrarray_t* pa = (ptrarray_t*)((plist_data_t)((node_t)father)->data)->hashtable;
         if (pa) {
             ptr_array_remove(pa, n);
         }
@@ -723,7 +727,7 @@
     if (iter)
     {
         *iter = malloc(sizeof(node_t));
-        *((node_t*)(*iter)) = node_first_child(node);
+        *((node_t*)(*iter)) = node_first_child((node_t)node);
     }
 }
 
@@ -751,7 +755,7 @@
     uint32_t ret = 0;
     if (node && PLIST_DICT == plist_get_node_type(node))
     {
-        ret = node_n_children(node) / 2;
+        ret = node_n_children((node_t)node) / 2;
     }
     return ret;
 }
@@ -761,7 +765,7 @@
     if (iter)
     {
         *iter = malloc(sizeof(node_t));
-        *((node_t*)(*iter)) = node_first_child(node);
+        *((node_t*)(*iter)) = node_first_child((node_t)node);
     }
 }
 
@@ -798,7 +802,7 @@
     plist_t father = plist_get_parent(node);
     if (PLIST_DICT == plist_get_node_type(father))
     {
-        plist_get_key_val( (plist_t) node_prev_sibling(node), key);
+        plist_get_key_val( (plist_t) node_prev_sibling((node_t)node), key);
     }
 }
 
@@ -808,7 +812,7 @@
     plist_t father = plist_get_parent(node);
     if (PLIST_DICT == plist_get_node_type(father))
     {
-        ret = (plist_t)node_prev_sibling(node);
+        ret = (plist_t)node_prev_sibling((node_t)node);
     }
     return ret;
 }
@@ -828,16 +832,16 @@
             ret = (plist_t)hash_table_lookup(ht, &sdata);
         } else {
             plist_t current = NULL;
-            for (current = (plist_t)node_first_child(node);
+            for (current = (plist_t)node_first_child((node_t)node);
                 current;
-                current = (plist_t)node_next_sibling(node_next_sibling(current)))
+                current = (plist_t)node_next_sibling(node_next_sibling((node_t)current)))
             {
                 data = plist_get_data(current);
                 assert( PLIST_KEY == plist_get_node_type(current) );
 
                 if (data && !strcmp(key, data->strval))
                 {
-                    ret = (plist_t)node_next_sibling(current);
+                    ret = (plist_t)node_next_sibling((node_t)current);
                     break;
                 }
             }
@@ -849,23 +853,23 @@
 void plist_dict_set_item(plist_t node, const char* key, plist_t item)
 {
     if (node && PLIST_DICT == plist_get_node_type(node)) {
-        node_t old_item = plist_dict_get_item(node, key);
+        plist_t old_item = plist_dict_get_item(node, key);
         plist_t key_node = NULL;
         if (old_item) {
-            int idx = plist_free_node(old_item);
+            int idx = plist_free_node((node_t)old_item);
             assert(idx >= 0);
             if (idx < 0) {
                 return;
             }
-            node_insert(node, idx, item);
-            key_node = node_prev_sibling(item);
+            node_insert((node_t)node, idx, (node_t)item);
+            key_node = node_prev_sibling((node_t)item);
         } else {
             key_node = plist_new_key(key);
-            node_attach(node, key_node);
-            node_attach(node, item);
+            node_attach((node_t)node, (node_t)key_node);
+            node_attach((node_t)node, (node_t)item);
         }
 
-        hashtable_t *ht = ((plist_data_t)((node_t)node)->data)->hashtable;
+        hashtable_t *ht = (hashtable_t*)((plist_data_t)((node_t)node)->data)->hashtable;
         if (ht) {
             /* store pointer to item in hash table */
             hash_table_insert(ht, (plist_data_t)((node_t)key_node)->data, item);
@@ -875,11 +879,11 @@
                 ht = hash_table_new(dict_key_hash, dict_key_compare, NULL);
                 /* calculate the hashes for all entries we have so far */
                 plist_t current = NULL;
-                for (current = (plist_t)node_first_child(node);
+                for (current = (plist_t)node_first_child((node_t)node);
                      ht && current;
-                     current = (plist_t)node_next_sibling(node_next_sibling(current)))
+                     current = (plist_t)node_next_sibling(node_next_sibling((node_t)current)))
                 {
-                    hash_table_insert(ht, ((node_t)current)->data, node_next_sibling(current));
+                    hash_table_insert(ht, ((node_t)current)->data, node_next_sibling((node_t)current));
                 }
                 ((plist_data_t)((node_t)node)->data)->hashtable = ht;
             }
@@ -894,8 +898,8 @@
         plist_t old_item = plist_dict_get_item(node, key);
         if (old_item)
         {
-            plist_t key_node = node_prev_sibling(old_item);
-            hashtable_t* ht = ((plist_data_t)((node_t)node)->data)->hashtable;
+            plist_t key_node = node_prev_sibling((node_t)old_item);
+            hashtable_t* ht = (hashtable_t*)((plist_data_t)((node_t)node)->data)->hashtable;
             if (ht) {
                 hash_table_remove(ht, ((node_t)key_node)->data);
             }
diff --git a/src/ptrarray.c b/src/ptrarray.c
index c499773..3a11031 100644
--- a/src/ptrarray.c
+++ b/src/ptrarray.c
@@ -45,7 +45,7 @@
 	if (!pa || !pa->pdata) return;
 	long remaining = pa->capacity-pa->len;
 	if (remaining == 0) {
-		pa->pdata = realloc(pa->pdata, sizeof(void*) * (pa->capacity + pa->capacity_step));
+		pa->pdata = (void**)realloc(pa->pdata, sizeof(void*) * (pa->capacity + pa->capacity_step));
 		pa->capacity += pa->capacity_step;
 	}
 	if (array_index < 0 || array_index >= pa->len) {
diff --git a/src/xplist.c b/src/xplist.c
index 4833a92..66e1dba 100644
--- a/src/xplist.c
+++ b/src/xplist.c
@@ -133,7 +133,7 @@
     return len;
 }
 
-static int node_to_xml(node_t node, bytearray_t **outbuf, uint32_t depth)
+static plist_err_t node_to_xml(node_t node, bytearray_t **outbuf, uint32_t depth)
 {
     plist_data_t node_data = NULL;
 
@@ -366,7 +366,7 @@
         }
         node_t ch;
         for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) {
-            int res = node_to_xml(ch, outbuf, depth+1);
+            plist_err_t res = node_to_xml(ch, outbuf, depth+1);
             if (res < 0) return res;
         }
 
@@ -444,7 +444,7 @@
     return n;
 }
 
-static int node_estimate_size(node_t node, uint64_t *size, uint32_t depth)
+static plist_err_t node_estimate_size(node_t node, uint64_t *size, uint32_t depth)
 {
     plist_data_t data;
     if (!node) {
@@ -532,13 +532,13 @@
 plist_err_t plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length)
 {
     uint64_t size = 0;
-    int res;
+    plist_err_t res;
 
     if (!plist || !plist_xml || !length) {
         return PLIST_ERR_INVALID_ARG;
     }
 
-    res = node_estimate_size(plist, &size, 0);
+    res = node_estimate_size((node_t)plist, &size, 0);
     if (res < 0) {
         return res;
     }
@@ -552,7 +552,7 @@
 
     str_buf_append(outbuf, XML_PLIST_PROLOG, sizeof(XML_PLIST_PROLOG)-1);
 
-    res = node_to_xml(plist, &outbuf, 0);
+    res = node_to_xml((node_t)plist, &outbuf, 0);
     if (res < 0) {
         str_buf_free(outbuf);
         *plist_xml = NULL;
@@ -562,7 +562,7 @@
 
     str_buf_append(outbuf, XML_PLIST_EPILOG, sizeof(XML_PLIST_EPILOG));
 
-    *plist_xml = outbuf->data;
+    *plist_xml = (char*)outbuf->data;
     *length = outbuf->len - 1;
 
     outbuf->data = NULL;
@@ -671,14 +671,14 @@
 {
     while (tp) {
         text_part_t *tmp = tp;
-        tp = tp->next;
+        tp = (text_part_t*)tp->next;
         free(tmp);
     }
 }
 
 static text_part_t* text_part_append(text_part_t* parts, const char *begin, size_t length, int is_cdata)
 {
-    text_part_t* newpart = malloc(sizeof(text_part_t));
+    text_part_t* newpart = (text_part_t*)malloc(sizeof(text_part_t));
     assert(newpart);
     parts->next = text_part_init(newpart, begin, length, is_cdata);
     return newpart;
@@ -930,9 +930,9 @@
     text_part_t *tmp = tp;
     while (tp && tp->begin) {
         total_length += tp->length;
-        tp = tp->next;
+        tp = (text_part_t*)tp->next;
     }
-    str = malloc(total_length + 1);
+    str = (char*)malloc(total_length + 1);
     assert(str);
     p = str;
     tp = tmp;
@@ -947,7 +947,7 @@
             }
         }
         p += len;
-        tp = tp->next;
+        tp = (text_part_t*)tp->next;
     }
     *p = '\0';
     if (length) {
@@ -959,7 +959,7 @@
     return str;
 }
 
-static int node_from_xml(parse_ctx ctx, plist_t *plist)
+static plist_err_t node_from_xml(parse_ctx ctx, plist_t *plist)
 {
     char *tag = NULL;
     char *keyname = NULL;
@@ -1067,7 +1067,7 @@
                 goto err_out;
             }
             int taglen = ctx->pos - p;
-            tag = malloc(taglen + 1);
+            tag = (char*)malloc(taglen + 1);
             strncpy(tag, p, taglen);
             tag[taglen] = '\0';
             if (*ctx->pos != '>') {
@@ -1105,7 +1105,7 @@
                     goto err_out;
                 }
 
-                struct node_path_item *path_item = malloc(sizeof(struct node_path_item));
+                struct node_path_item *path_item = (struct node_path_item*)malloc(sizeof(struct node_path_item));
                 if (!path_item) {
                     PLIST_XML_ERR("out of memory when allocating node path item\n");
                     ctx->err++;
@@ -1133,7 +1133,7 @@
                     goto err_out;
                 }
                 struct node_path_item *path_item = node_path;
-                node_path = node_path->prev;
+                node_path = (struct node_path_item*)node_path->prev;
                 free(path_item);
 
                 free(tag);
@@ -1156,7 +1156,7 @@
                     text_part_t *tp = get_text_parts(ctx, tag, taglen, 1, &first_part);
                     if (!tp) {
                         PLIST_XML_ERR("Could not parse text content for '%s' node\n", tag);
-                        text_parts_free(first_part.next);
+                        text_parts_free((text_part_t*)first_part.next);
                         ctx->err++;
                         goto err_out;
                     }
@@ -1165,7 +1165,7 @@
                         char *str_content = text_parts_get_content(tp, 0, NULL, &requires_free);
                         if (!str_content) {
                             PLIST_XML_ERR("Could not get text content for '%s' node\n", tag);
-                            text_parts_free(first_part.next);
+                            text_parts_free((text_part_t*)first_part.next);
                             ctx->err++;
                             goto err_out;
                         }
@@ -1194,7 +1194,7 @@
                     } else {
                         is_empty = 1;
                     }
-                    text_parts_free(tp->next);
+                    text_parts_free((text_part_t*)tp->next);
                 }
                 if (is_empty) {
                     data->intval = 0;
@@ -1207,7 +1207,7 @@
                     text_part_t *tp = get_text_parts(ctx, tag, taglen, 1, &first_part);
                     if (!tp) {
                         PLIST_XML_ERR("Could not parse text content for '%s' node\n", tag);
-                        text_parts_free(first_part.next);
+                        text_parts_free((text_part_t*)first_part.next);
                         ctx->err++;
                         goto err_out;
                     }
@@ -1216,7 +1216,7 @@
                         char *str_content = text_parts_get_content(tp, 0, NULL, &requires_free);
                         if (!str_content) {
                             PLIST_XML_ERR("Could not get text content for '%s' node\n", tag);
-                            text_parts_free(first_part.next);
+                            text_parts_free((text_part_t*)first_part.next);
                             ctx->err++;
                             goto err_out;
                         }
@@ -1225,7 +1225,7 @@
                             free(str_content);
                         }
                     }
-                    text_parts_free(tp->next);
+                    text_parts_free((text_part_t*)tp->next);
                 }
                 data->type = PLIST_REAL;
                 data->length = 8;
@@ -1251,12 +1251,12 @@
                     size_t length = 0;
                     if (!tp) {
                         PLIST_XML_ERR("Could not parse text content for '%s' node\n", tag);
-                        text_parts_free(first_part.next);
+                        text_parts_free((text_part_t*)first_part.next);
                         ctx->err++;
                         goto err_out;
                     }
                     str = text_parts_get_content(tp, 1, &length, NULL);
-                    text_parts_free(first_part.next);
+                    text_parts_free((text_part_t*)first_part.next);
                     if (!str) {
                         PLIST_XML_ERR("Could not get text content for '%s' node\n", tag);
                         ctx->err++;
@@ -1284,7 +1284,7 @@
                     text_part_t *tp = get_text_parts(ctx, tag, taglen, 1, &first_part);
                     if (!tp) {
                         PLIST_XML_ERR("Could not parse text content for '%s' node\n", tag);
-                        text_parts_free(first_part.next);
+                        text_parts_free((text_part_t*)first_part.next);
                         ctx->err++;
                         goto err_out;
                     }
@@ -1293,7 +1293,7 @@
                         char *str_content = text_parts_get_content(tp, 0, NULL, &requires_free);
                         if (!str_content) {
                             PLIST_XML_ERR("Could not get text content for '%s' node\n", tag);
-                            text_parts_free(first_part.next);
+                            text_parts_free((text_part_t*)first_part.next);
                             ctx->err++;
                             goto err_out;
                         }
@@ -1307,7 +1307,7 @@
                             free(str_content);
                         }
                     }
-                    text_parts_free(tp->next);
+                    text_parts_free((text_part_t*)tp->next);
                 }
                 data->type = PLIST_DATA;
             } else if (!strcmp(tag, XPLIST_DATE)) {
@@ -1316,7 +1316,7 @@
                     text_part_t *tp = get_text_parts(ctx, tag, taglen, 1, &first_part);
                     if (!tp) {
                         PLIST_XML_ERR("Could not parse text content for '%s' node\n", tag);
-                        text_parts_free(first_part.next);
+                        text_parts_free((text_part_t*)first_part.next);
                         ctx->err++;
                         goto err_out;
                     }
@@ -1327,7 +1327,7 @@
                         char *str_content = text_parts_get_content(tp, 0, &length, &requires_free);
                         if (!str_content) {
                             PLIST_XML_ERR("Could not get text content for '%s' node\n", tag);
-                            text_parts_free(first_part.next);
+                            text_parts_free((text_part_t*)first_part.next);
                             ctx->err++;
                             goto err_out;
                         }
@@ -1347,7 +1347,7 @@
                             free(str_content);
                         }
                     }
-                    text_parts_free(tp->next);
+                    text_parts_free((text_part_t*)tp->next);
                     data->realval = (double)(timev - MAC_EPOCH);
                 }
                 data->length = sizeof(double);
@@ -1391,7 +1391,7 @@
                     }
                 }
                 if (!is_empty && (data->type == PLIST_DICT || data->type == PLIST_ARRAY)) {
-                    struct node_path_item *path_item = malloc(sizeof(struct node_path_item));
+                    struct node_path_item *path_item = (struct node_path_item*)malloc(sizeof(struct node_path_item));
                     if (!path_item) {
                         PLIST_XML_ERR("out of memory when allocating node path item\n");
                         ctx->err++;
@@ -1416,7 +1416,7 @@
                     goto err_out;
                 }
                 struct node_path_item *path_item = node_path;
-                node_path = node_path->prev;
+                node_path = (struct node_path_item*)node_path->prev;
                 free(path_item);
 
                 parent = ((node_t)parent)->parent;
@@ -1447,7 +1447,7 @@
     /* clean up node_path if required */
     while (node_path) {
         struct node_path_item *path_item = node_path;
-        node_path = path_item->prev;
+        node_path = (struct node_path_item*)path_item->prev;
         free(path_item);
     }