fix value_offset

This commit is contained in:
mykola2312 2022-05-03 07:59:34 +03:00
parent 900341c5b7
commit 1619e3234e
2 changed files with 4 additions and 6 deletions

View file

@ -27,9 +27,7 @@ uint value_size(struct cu_struct_s* st, uint idx, const void* in)
uint value_offset(struct cu_struct_s* st, uint idx, const void* in) uint value_offset(struct cu_struct_s* st, uint idx, const void* in)
{ {
uint offset = 0; uint offset = 0;
do { while (idx--) offset += value_size(st, idx, in);
offset += value_size(st, idx, in);
} while (idx--);
return offset; return offset;
} }

6
test.c
View file

@ -15,7 +15,7 @@ struct test_s {
uint32_t array1[12]; uint32_t array1[12];
uint16_t count; uint16_t count;
item_t array2[5]; item_t array2[5];
} test = { } __attribute__((packed)) test = {
.seq = {0}, .seq = {0},
.array1 = {0}, .array1 = {0},
.count = 5, .count = 5,
@ -106,8 +106,8 @@ int main()
printf("%lx\t%lx\n", 0x12345678abcd8765, h64ton64(0x12345678abcd8765)); printf("%lx\t%lx\n", 0x12345678abcd8765, h64ton64(0x12345678abcd8765));
printf("[struct]\n"); printf("[struct]\n");
printf("value_offset\t%u\n", value_offset(CU_STRUCT(test_s), 0, &test)); printf("value_offset\t%u\n", value_offset(CU_STRUCT(test_s), 1, &test));
printf("value_size\t%u\n", value_size(CU_STRUCT(test_s), 0, &test)); printf("value_size\t%u\n", value_size(CU_STRUCT(test_s), 1, &test));
cutil_exit(); cutil_exit();
return 0; return 0;