From 1619e3234e769a1fc7cd750ada0d39e582b5d762 Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Tue, 3 May 2022 07:59:34 +0300 Subject: [PATCH] fix value_offset --- struct.c | 4 +--- test.c | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/struct.c b/struct.c index 8323995..886c1eb 100644 --- a/struct.c +++ b/struct.c @@ -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 offset = 0; - do { - offset += value_size(st, idx, in); - } while (idx--); + while (idx--) offset += value_size(st, idx, in); return offset; } diff --git a/test.c b/test.c index ac45436..f5c8041 100644 --- a/test.c +++ b/test.c @@ -15,7 +15,7 @@ struct test_s { uint32_t array1[12]; uint16_t count; item_t array2[5]; -} test = { +} __attribute__((packed)) test = { .seq = {0}, .array1 = {0}, .count = 5, @@ -106,8 +106,8 @@ int main() printf("%lx\t%lx\n", 0x12345678abcd8765, h64ton64(0x12345678abcd8765)); printf("[struct]\n"); - printf("value_offset\t%u\n", value_offset(CU_STRUCT(test_s), 0, &test)); - printf("value_size\t%u\n", value_size(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), 1, &test)); cutil_exit(); return 0;