From 968fbbb4c99060bde7a9d90da0d490d3bdbf0d48 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Mon, 2 Mar 2026 21:04:47 -0800 Subject: [PATCH] Fix a compilation error by clang-17 (#4812) * Fix a compilation error by clang-17 ``` variable-sized object may not be initialized ``` clang-17 is the default version on MacOS Tahoe(26.2) on AppleM1 --- .../linear_memory_wasm_test.cc | 10 +- tests/unit/shared-heap/shared_heap_test.cc | 214 ++++++++++++++---- 2 files changed, 175 insertions(+), 49 deletions(-) diff --git a/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc b/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc index a5db0e033..1bdd6308b 100644 --- a/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc +++ b/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc @@ -133,23 +133,25 @@ destroy_module_env(struct ret_env module_env) TEST_F(TEST_SUITE_NAME, test_wasm_mem_page_count) { struct ret_env tmp_module_env; - unsigned int num_normal_wasm = 9; - unsigned int num_error_wasm = 10; - const char *wasm_file_normal[num_normal_wasm] = { + const char *wasm_file_normal[9] = { "/wasm_mem_page_01.wasm", "/wasm_mem_page_02.wasm", "/wasm_mem_page_05.wasm", "/wasm_mem_page_07.wasm", "/wasm_mem_page_08.wasm", "/wasm_mem_page_09.wasm", "/wasm_mem_page_10.wasm", "/wasm_mem_page_12.wasm", "/wasm_mem_page_14.wasm" }; + unsigned int num_normal_wasm = + sizeof(wasm_file_normal) / sizeof(wasm_file_normal[0]); - const char *wasm_file_error[num_error_wasm] = { + const char *wasm_file_error[10] = { "/wasm_mem_page_03.wasm", "/wasm_mem_page_04.wasm", "/wasm_mem_page_06.wasm", "/wasm_mem_page_11.wasm", "/wasm_mem_page_13.wasm", "/wasm_mem_page_15.wasm", "/wasm_mem_page_16.wasm", "/wasm_mem_page_17.wasm", "/wasm_mem_page_18.wasm", "/wasm_mem_page_19.wasm" }; + unsigned int num_error_wasm = + sizeof(wasm_file_error) / sizeof(wasm_file_error[0]); // Test normal wasm file. for (int i = 0; i < num_normal_wasm; i++) { diff --git a/tests/unit/shared-heap/shared_heap_test.cc b/tests/unit/shared-heap/shared_heap_test.cc index 4b5a8e991..6aa933d0f 100644 --- a/tests/unit/shared-heap/shared_heap_test.cc +++ b/tests/unit/shared-heap/shared_heap_test.cc @@ -11,6 +11,7 @@ #include "bh_platform.h" #include +#include class shared_heap_test : public testing::Test { @@ -195,10 +196,15 @@ TEST_F(shared_heap_test, test_preallocated_shared_heap_malloc_fail) SharedHeapInitArgs args = {}; WASMSharedHeap *shared_heap = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); /* create a preallocated shared heap */ - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap = wasm_runtime_create_shared_heap(&args); if (!shared_heap) { @@ -329,10 +335,15 @@ TEST_F(shared_heap_test, test_shared_heap_rmw) { WASMSharedHeap *shared_heap = nullptr; uint32 argv[2] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE] = {}; + uint8 *preallocated_buf_ptr = nullptr; uint32 start1, end1; - create_test_shared_heap(preallocated_buf, BUF_SIZE, &shared_heap); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + + create_test_shared_heap(preallocated_buf_ptr, BUF_SIZE, &shared_heap); /* app addr for shared heap */ start1 = UINT32_MAX - BUF_SIZE + 1; @@ -368,11 +379,21 @@ TEST_F(shared_heap_test, test_shared_heap_chain_rmw) SharedHeapInitArgs args = {}; WASMSharedHeap *shared_heap_chain = nullptr; uint32 argv[2] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE] = {}, preallocated_buf2[BUF_SIZE] = {}; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; uint32 start1, end1, start2, end2; - create_test_shared_heap_chain(preallocated_buf, BUF_SIZE, preallocated_buf2, - BUF_SIZE, &shared_heap_chain); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); + + create_test_shared_heap_chain(preallocated_buf_ptr, BUF_SIZE, + preallocated_buf2_ptr, BUF_SIZE, + &shared_heap_chain); /* app addr for shared heap */ start1 = UINT32_MAX - 2 * BUF_SIZE + 1; @@ -416,11 +437,21 @@ TEST_F(shared_heap_test, test_shared_heap_chain_rmw_bulk_memory) SharedHeapInitArgs args = {}; WASMSharedHeap *shared_heap_chain = nullptr; uint32 argv[3] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE] = {}, preallocated_buf2[BUF_SIZE] = {}; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; uint32 start1, end1, start2, end2; - create_test_shared_heap_chain(preallocated_buf, BUF_SIZE, preallocated_buf2, - BUF_SIZE, &shared_heap_chain); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); + + create_test_shared_heap_chain(preallocated_buf_ptr, BUF_SIZE, + preallocated_buf2_ptr, BUF_SIZE, + &shared_heap_chain); /* app addr for shared heap */ start1 = UINT32_MAX - 2 * BUF_SIZE + 1; @@ -471,11 +502,21 @@ TEST_F(shared_heap_test, test_shared_heap_chain_rmw_bulk_memory_oob) SharedHeapInitArgs args = {}; WASMSharedHeap *shared_heap_chain = nullptr; uint32 argv[3] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE] = {}, preallocated_buf2[BUF_SIZE] = {}; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; uint32 start1, end1, start2, end2; - create_test_shared_heap_chain(preallocated_buf, BUF_SIZE, preallocated_buf2, - BUF_SIZE, &shared_heap_chain); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); + + create_test_shared_heap_chain(preallocated_buf_ptr, BUF_SIZE, + preallocated_buf2_ptr, BUF_SIZE, + &shared_heap_chain); /* app addr for shared heap */ start1 = UINT32_MAX - 2 * BUF_SIZE + 1; @@ -553,10 +594,19 @@ TEST_F(shared_heap_test, test_shared_heap_rmw_oob) { WASMSharedHeap *shared_heap = nullptr; uint32 argv[2] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE], preallocated_buf2[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; uint32 start1, end1, start2, end2; - create_test_shared_heap(preallocated_buf, BUF_SIZE, &shared_heap); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); + + create_test_shared_heap(preallocated_buf_ptr, BUF_SIZE, &shared_heap); /* app addr for shared heap */ start1 = UINT32_MAX - BUF_SIZE + 1; @@ -587,11 +637,21 @@ TEST_F(shared_heap_test, test_shared_heap_chain_rmw_oob) { WASMSharedHeap *shared_heap_chain = nullptr; uint32 argv[2] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE], preallocated_buf2[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; uint32 start1, end1, start2, end2; - create_test_shared_heap_chain(preallocated_buf, BUF_SIZE, preallocated_buf2, - BUF_SIZE, &shared_heap_chain); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); + + create_test_shared_heap_chain(preallocated_buf_ptr, BUF_SIZE, + preallocated_buf2_ptr, BUF_SIZE, + &shared_heap_chain); /* app addr for shared heap */ start1 = UINT32_MAX - 2 * BUF_SIZE + 1; @@ -620,11 +680,21 @@ TEST_F(shared_heap_test, test_shared_heap_chain_memory64_rmw) { WASMSharedHeap *shared_heap_chain = nullptr; uint32 argv[3] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE] = {}, preallocated_buf2[BUF_SIZE] = {}; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; uint64 start1, end1, start2, end2; - create_test_shared_heap_chain(preallocated_buf, BUF_SIZE, preallocated_buf2, - BUF_SIZE, &shared_heap_chain); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); + + create_test_shared_heap_chain(preallocated_buf_ptr, BUF_SIZE, + preallocated_buf2_ptr, BUF_SIZE, + &shared_heap_chain); /* app addr for shared heap */ start1 = UINT64_MAX - 2 * BUF_SIZE + 1; @@ -667,11 +737,21 @@ TEST_F(shared_heap_test, test_shared_heap_chain_memory64_rmw_oob) { WASMSharedHeap *shared_heap_chain = nullptr; uint32 argv[3] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE], preallocated_buf2[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; uint64 start1, end1, start2, end2; - create_test_shared_heap_chain(preallocated_buf, BUF_SIZE, preallocated_buf2, - BUF_SIZE, &shared_heap_chain); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); + + create_test_shared_heap_chain(preallocated_buf_ptr, BUF_SIZE, + preallocated_buf2_ptr, BUF_SIZE, + &shared_heap_chain); /* app addr for shared heap */ start1 = UINT64_MAX - 2 * BUF_SIZE + 1; @@ -759,7 +839,11 @@ TEST_F(shared_heap_test, test_addr_conv_pre_allocated_oob) WASMSharedHeap *shared_heap = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(), app_addr = 0xFFFFFFFF - BUF_SIZE; - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); bool ret = false; /* create a preallocated shared heap */ @@ -769,7 +853,7 @@ TEST_F(shared_heap_test, test_addr_conv_pre_allocated_oob) FAIL() << "Failed to register natives"; } - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap = wasm_runtime_create_shared_heap(&args); if (!shared_heap) { @@ -799,7 +883,11 @@ TEST_F(shared_heap_test, test_shared_heap_chain) WASMSharedHeap *shared_heap = nullptr, *shared_heap2 = nullptr, *shared_heap_chain = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); bool ret = false; ret = wasm_native_register_natives("env", g_test_native_symbols, @@ -816,7 +904,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain) /* create a preallocated shared heap */ memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap2 = wasm_runtime_create_shared_heap(&args); if (!shared_heap2) { @@ -865,7 +953,11 @@ TEST_F(shared_heap_test, test_shared_heap_chain_create_fail2) WASMSharedHeap *shared_heap = nullptr, *shared_heap2 = nullptr, *shared_heap_chain = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); struct ret_env tmp_module_env; args.size = 1024; @@ -875,7 +967,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_create_fail2) } memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap2 = wasm_runtime_create_shared_heap(&args); if (!shared_heap2) { @@ -907,7 +999,15 @@ TEST_F(shared_heap_test, test_shared_heap_chain_create_fail3) WASMSharedHeap *shared_heap = nullptr, *shared_heap2 = nullptr, *shared_heap3 = nullptr, *shared_heap_chain = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE], preallocated_buf2[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); args.size = 1024; shared_heap = wasm_runtime_create_shared_heap(&args); @@ -916,7 +1016,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_create_fail3) } memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap2 = wasm_runtime_create_shared_heap(&args); if (!shared_heap2) { @@ -930,7 +1030,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_create_fail3) } memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf2; + args.pre_allocated_addr = preallocated_buf2_ptr; args.size = BUF_SIZE; shared_heap3 = wasm_runtime_create_shared_heap(&args); if (!shared_heap3) { @@ -952,7 +1052,15 @@ TEST_F(shared_heap_test, test_shared_heap_chain_unchain) WASMSharedHeap *shared_heap = nullptr, *shared_heap2 = nullptr, *shared_heap3 = nullptr, *shared_heap_chain = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE], preallocated_buf2[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); args.size = 1024; shared_heap = wasm_runtime_create_shared_heap(&args); @@ -961,7 +1069,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_unchain) } memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap2 = wasm_runtime_create_shared_heap(&args); if (!shared_heap2) { @@ -975,7 +1083,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_unchain) } memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf2; + args.pre_allocated_addr = preallocated_buf2_ptr; args.size = BUF_SIZE; shared_heap3 = wasm_runtime_create_shared_heap(&args); if (!shared_heap3) { @@ -1007,7 +1115,11 @@ TEST_F(shared_heap_test, test_shared_heap_chain_reset_runtime_managed) uint64 offset = 0, offset_after_reset = 0; void *native_ptr = nullptr, *native_ptr_after_reset = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); struct ret_env tmp_module_env; args.size = 4096; @@ -1017,7 +1129,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_reset_runtime_managed) } args.size = BUF_SIZE; - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; shared_heap2 = wasm_runtime_create_shared_heap(&args); if (!shared_heap2) { FAIL() << "Failed to create second shared heap"; @@ -1085,17 +1197,21 @@ TEST_F(shared_heap_test, test_shared_heap_chain_reset_preallocated) SharedHeapInitArgs args = {}; WASMSharedHeap *shared_heap = nullptr; uint32 BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); uint8 set_val = 0xA5; - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap = wasm_runtime_create_shared_heap(&args); if (!shared_heap) { FAIL() << "Create preallocated shared heap failed.\n"; } - memset(preallocated_buf, set_val, BUF_SIZE); + memset(preallocated_buf_ptr, set_val, BUF_SIZE); for (uint32 i = 0; i < BUF_SIZE; i++) { EXPECT_EQ(set_val, preallocated_buf[i]); } @@ -1146,7 +1262,11 @@ TEST_F(shared_heap_test, test_shared_heap_chain_addr_conv) WASMSharedHeap *shared_heap = nullptr, *shared_heap2 = nullptr, *shared_heap_chain = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); bool ret = false; ret = wasm_native_register_natives("env", g_test_native_symbols, @@ -1163,7 +1283,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_addr_conv) /* create a preallocated shared heap */ memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap2 = wasm_runtime_create_shared_heap(&args); if (!shared_heap2) { @@ -1203,7 +1323,11 @@ TEST_F(shared_heap_test, test_shared_heap_chain_addr_conv_oob) WASMSharedHeap *shared_heap = nullptr, *shared_heap2 = nullptr, *shared_heap_chain = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); bool ret = false; ret = wasm_native_register_natives("env", g_test_native_symbols, @@ -1220,7 +1344,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_addr_conv_oob) /* create a preallocated shared heap */ memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap2 = wasm_runtime_create_shared_heap(&args); if (!shared_heap2) {