From d0eabb0b94401ebb06e24d867ee266fbd54d8900 Mon Sep 17 00:00:00 2001 From: lyon Date: Wed, 5 Jan 2022 22:36:28 +0800 Subject: [PATCH] set size of arg to uint32_t to aline to 4 --- port/linux/.vscode/launch.json | 2 ++ port/linux/test/content-test.cpp | 12 ++++++------ src/dataArg.c | 12 ++++++------ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/port/linux/.vscode/launch.json b/port/linux/.vscode/launch.json index 21471cdcc..fbdd48625 100644 --- a/port/linux/.vscode/launch.json +++ b/port/linux/.vscode/launch.json @@ -18,6 +18,8 @@ "program": "${workspaceFolder}/build/test/pikascript_test", // "program": "${workspaceFolder}/../build/src/boot/demo06-pikamain/pikascript_demo06-pikamain", "args": [ + // "--gtest_filter=arg_test*", + "--gtest_filter=content*", // "--gtest_filter=pikaMain.print_in_def", // "--gtest_filter=pikaMain.list_for_loop" // "--gtest_filter=pikaMain.err_scop" diff --git a/port/linux/test/content-test.cpp b/port/linux/test/content-test.cpp index 5f969a6f4..7be2dd7a2 100644 --- a/port/linux/test/content-test.cpp +++ b/port/linux/test/content-test.cpp @@ -22,15 +22,15 @@ TEST(content, init) { uint16_t size = content_getSize(self); uint8_t* content = content_getContent(self); - ASSERT_EQ(contentOffset, 14); - ASSERT_EQ(typeOffset, 18); + ASSERT_EQ(contentOffset, 16); + ASSERT_EQ(typeOffset, 20); ASSERT_EQ(sizeOffset, 8); ASSERT_EQ(size, 4); ASSERT_EQ(content[0], 1); ASSERT_EQ(content[1], 2); ASSERT_EQ(content[2], 3); ASSERT_EQ(content[3], 4); - ASSERT_EQ(totleSize, 22); + ASSERT_EQ(totleSize, 24); ASSERT_EQ(hash_time33((char*)"name"), nameHash); ASSERT_EQ(TYPE_NONE, type); @@ -60,15 +60,15 @@ TEST(content, set) { uint16_t size = content_getSize(self); uint8_t* content = content_getContent(self); - ASSERT_EQ(contentOffset, 14); - ASSERT_EQ(typeOffset, 18); + ASSERT_EQ(contentOffset, 16); + ASSERT_EQ(typeOffset, 20); ASSERT_EQ(sizeOffset, 8); ASSERT_EQ(size, 4); ASSERT_EQ(content[0], 1); ASSERT_EQ(content[1], 2); ASSERT_EQ(content[2], 3); ASSERT_EQ(content[3], 4); - ASSERT_EQ(totleSize, 22); + ASSERT_EQ(totleSize, 24); ASSERT_EQ(hash_time33((char*)"name"), nameHash); ASSERT_EQ(TYPE_NONE, type); diff --git a/src/dataArg.c b/src/dataArg.c index 2abcb42e8..3b325dff4 100644 --- a/src/dataArg.c +++ b/src/dataArg.c @@ -76,10 +76,10 @@ Hash hash_time33(char* str) { uint8_t* content_init_hash(Hash nameHash, ArgType type, uint8_t* content, - uint16_t size, + uint32_t size, uint8_t* next) { const uint8_t nextLength = sizeof(uint8_t*); - const uint8_t sizeLength = sizeof(uint16_t); + const uint8_t sizeLength = sizeof(uint32_t); uint16_t nameSize = sizeof(Hash); // use hash uint16_t typeSize = sizeof(ArgType); // use enum uint8_t* self = (uint8_t*)pikaMalloc(nextLength + sizeLength + nameSize + @@ -121,7 +121,7 @@ uint8_t* content_init(char* name, } uint16_t content_totleSize(uint8_t* self) { - const uint8_t size_size = sizeof(uint16_t); + const uint8_t size_size = sizeof(uint32_t); const uint8_t size_next = sizeof(uint8_t*); const uint8_t size_type = sizeof(ArgType); const uint8_t size_hash = sizeof(Hash); @@ -137,7 +137,7 @@ void arg_freeContent(Arg* self) { uint8_t content_nameOffset(uint8_t* self) { const uint8_t nextLength = sizeof(uint8_t*); - const uint8_t sizeLength = sizeof(uint16_t); + const uint8_t sizeLength = sizeof(uint32_t); return nextLength + sizeLength; } @@ -239,7 +239,7 @@ ArgType content_getType(uint8_t* self) { uint16_t content_contentOffset(uint8_t* self) { const uint8_t nextLength = sizeof(uint8_t*); - const uint8_t sizeLength = sizeof(uint16_t); + const uint8_t sizeLength = sizeof(uint32_t); return nextLength + sizeLength + sizeof(Hash); } @@ -360,7 +360,7 @@ char* arg_getStr(Arg* self) { uint16_t content_typeOffset(uint8_t* self) { const uint8_t nextLength = sizeof(uint8_t*); - const uint8_t sizeLength = 2; + const uint8_t sizeLength = sizeof(uint32_t); uint16_t size = content_getSize(self); uint16_t nameSize = sizeof(Hash); return nextLength + sizeLength + nameSize + size;