summaryrefslogtreecommitdiff
path: root/src/libecbor/ecbor_encoder.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libecbor/ecbor_encoder.c')
-rw-r--r--src/libecbor/ecbor_encoder.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/libecbor/ecbor_encoder.c b/src/libecbor/ecbor_encoder.c
index 9d4c4a2..0899660 100644
--- a/src/libecbor/ecbor_encoder.c
+++ b/src/libecbor/ecbor_encoder.c
@@ -563,25 +563,20 @@ ecbor_map (ecbor_item_t *map, ecbor_item_t *keys, ecbor_item_t *values,
map->is_indefinite = false;
map->type = ECBOR_TYPE_MAP;
- map->length = length;
+ map->length = length * 2;
if (length > 0) {
ECBOR_INTERNAL_CHECK_ITEM_PTR (keys);
ECBOR_INTERNAL_CHECK_ITEM_PTR (values);
map->child = keys;
- keys->parent = map;
- keys->next = values;
- values->parent = map;
- keys ++;
- values ++;
-
- for (i = 1; i < length; i ++) {
- values->next = (keys + 1);
- keys ++;
- keys->next = (values + 1);
- values ++;
+ for (i = 0; i < length; i ++, keys ++, values ++) {
+ keys->parent = map;
+ values->parent = map;
+ keys->next = values;
+ values->next = keys + 1;
}
+ values->next = NULL;
}
return ECBOR_OK;