summaryrefslogtreecommitdiff
path: root/src/nbt/read.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nbt/read.c')
-rw-r--r--src/nbt/read.c32
1 files changed, 12 insertions, 20 deletions
diff --git a/src/nbt/read.c b/src/nbt/read.c
index cef04ca..38f8b14 100644
--- a/src/nbt/read.c
+++ b/src/nbt/read.c
@@ -118,44 +118,36 @@ static bool nbt_read_list(tagdata_t *data, const stream_t *stream) {
}
static bool nbt_read_compound(tagdata_t *data, const stream_t *stream) {
- int32_t size = 0;
- int32_t capacity = 8;
- tag_t *tags = xalloc(capacity * sizeof(tag_t));
+
+ map_t map;
+ map_init(&map);
while (1) {
tag_t tag;
if (nbt_read_header(&tag, stream, true) == false) {
- free(tags);
+ map_free(&map);
return false;
}
-
+
+ if (tag.type == TAG_END)
+ break;
+
if (tag.name_len < 1) {
- free(tags);
+ map_free(&map);
return false;
}
- if (tag.type == TAG_END)
- break;
-
if (nbt_read_data(&tag, stream) == false) {
- free(tags);
+ map_free(&map);
return false;
}
-
- if (size == capacity) {
- capacity *= 2;
- tags = xrealloc(tags, capacity * sizeof(tag_t));
- }
- tags[size++] = tag;
+ map_put(&map, &tag);
}
- data->compound.size = size;
- data->compound.tags = xalloc(size * sizeof(tag_t));
- memcpy(data->compound.tags, tags, size * sizeof(tag_t));
- free(tags);
+ data->compound = map;
return true;
}