diff options
| author | Vasile Vilvoiu <vasi@vilvoiu.ro> | 2021-11-28 22:36:59 +0200 |
|---|---|---|
| committer | Vasile Vilvoiu <vasi@vilvoiu.ro> | 2021-11-28 22:36:59 +0200 |
| commit | fa14e043a604dfa17f45cf401cbcbeb4fb33693c (patch) | |
| tree | e402f56ce792ff62d77d13ffd86dd178b00d89ad | |
| parent | b7f2b7896d79a4360008280b7b2466df74d8e469 (diff) | |
Fix building of maps.
| -rw-r--r-- | src/libecbor/ecbor_encoder.c | 19 |
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; |
