Permalink
Browse files

free/clone/filter int arrays properly

  • Loading branch information...
1 parent a886f0b commit 2917bf22b9187b8b58caaf0a3f451bbb29c10605 @zydeco committed Mar 4, 2012
Showing with 29 additions and 0 deletions.
  1. +29 −0 nbt_treeops.c
View
@@ -63,6 +63,9 @@ void nbt_free(nbt_node* tree)
else if(tree->type == TAG_BYTE_ARRAY)
free(tree->payload.tag_byte_array.data);
+ else if(tree->type == TAG_INT_ARRAY)
+ free(tree->payload.tag_int_array.data);
+
else if(tree->type == TAG_STRING)
free(tree->payload.tag_string);
@@ -145,6 +148,19 @@ nbt_node* nbt_clone(nbt_node* tree)
ret->payload.tag_byte_array.length = tree->payload.tag_byte_array.length;
}
+ else if(tree->type == TAG_INT_ARRAY)
+ {
+ int32_t* newbuf;
+ CHECKED_MALLOC(newbuf, 4*tree->payload.tag_int_array.length, goto clone_error);
+
+ memcpy(newbuf,
+ tree->payload.tag_int_array.data,
+ 4*tree->payload.tag_int_array.length);
+
+ ret->payload.tag_int_array.data = newbuf;
+ ret->payload.tag_int_array.length = tree->payload.tag_int_array.length;
+ }
+
else if(tree->type == TAG_LIST)
{
ret->payload.tag_list.list = clone_list(tree->payload.tag_list.list);
@@ -273,6 +289,19 @@ nbt_node* nbt_filter(const nbt_node* tree, nbt_predicate_t filter, void* aux)
ret->payload.tag_byte_array.length = tree->payload.tag_byte_array.length;
}
+ else if(tree->type == TAG_INT_ARRAY)
+ {
+ CHECKED_MALLOC(ret->payload.tag_int_array.data,
+ 4*tree->payload.tag_int_array.length,
+ goto filter_error);
+
+ memcpy(ret->payload.tag_int_array.data,
+ tree->payload.tag_int_array.data,
+ tree->payload.tag_int_array.length);
+
+ ret->payload.tag_int_array.length = tree->payload.tag_int_array.length;
+ }
+
/* Okay, we want to keep this node, but keep traversing the tree! */
else if(tree->type == TAG_LIST)
{

0 comments on commit 2917bf2

Please sign in to comment.