diff options
-rw-r--r-- | rt_struct.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/rt_struct.c b/rt_struct.c index 4117def..b4840ac 100644 --- a/rt_struct.c +++ b/rt_struct.c @@ -26,6 +26,16 @@ static size_t member_size(rts_member *member) { return size; } +static int member_count(rts_type *type) { + if (type == NULL || type->members == NULL) { + return -1; + } else { + int i; + for (i = 0; type->members[i] != NULL; ++i); + return i; + } +} + int create_rts(rts_type *type) { if (type == NULL) { return 1; @@ -42,8 +52,14 @@ int create_rts(rts_type *type) { size_t max_align = 0; size_t remainder = 0; size_t padding = 0; + const int num_members = member_count(type); rts_member **members = type->members; + if (type->offsets == NULL) { + type->offsets = calloc(num_members+1, sizeof(size_t)); + type->offsets[num_members] = -1; + } + for (int i = 0; members[i] != NULL; ++i) { if (create_rts(members[i]->type)) { return 1; |