diff options
author | pommicket <pommicket@gmail.com> | 2022-12-05 19:05:14 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-05 19:05:14 -0500 |
commit | 05862b802237df8bc61b0b45ef1ba4e70b0773f5 (patch) | |
tree | 2bfcd1a2915bd4907652f29453c92e40deaac3d0 /arr.c | |
parent | 10c753107c6d9f9c90fef18b887b92c2290ca97d (diff) |
full json parser
Diffstat (limited to 'arr.c')
-rw-r--r-- | arr.c | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -60,6 +60,10 @@ static inline u32 arr_len(void *arr) { return arr ? arr_hdr_(arr)->len : 0; } +static inline u32 arr_cap(void *arr) { + return arr ? arr_hdr_(arr)->cap : 0; +} + static inline unsigned arr_lenu(void *arr) { return (unsigned)arr_len(arr); } @@ -114,6 +118,7 @@ static void arr_reserve_(void **arr, size_t member_size, size_t n) { if (!*arr) { // create a new array with capacity n+1 + // why n+1? i dont know i wrote this a while ago ArrHeader *hdr = calloc(1, sizeof(ArrHeader) + (n+1) * member_size); if (hdr) { hdr->cap = (u32)n+1; @@ -151,7 +156,7 @@ static void arr_set_len_(void **arr, size_t member_size, size_t n) { ArrHeader *hdr = arr_hdr_(*arr); if (n > hdr->len) { // zero new elements - memset((char *)hdr->data + hdr->len, 0, (n - hdr->len) * member_size); + memset((char *)hdr->data + hdr->len * member_size, 0, (n - hdr->len) * member_size); } hdr->len = (u32)n; } |