diff --git a/CMakeLists.txt b/CMakeLists.txt index 35e4e8dad17779ecf7110f5454c4724bf896c1d3..a61a37ae32068958b8c6c445e4e18072f1044ee2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.2) project(distributed_ut VERSION 1.0.0) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++17 -pthread") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++17 -pthread -Werror=vla") add_compile_options(-Werror=sign-compare -Werror=unused-variable) add_compile_options(-Wno-conversion-null) diff --git a/frameworks/libs/distributeddb/BUILD.gn b/frameworks/libs/distributeddb/BUILD.gn index b85586a8d069b5d7c08e0c463e123c7120a7fa92..f288cc35f5164eaea01eada5290bc5f84a82b14f 100644 --- a/frameworks/libs/distributeddb/BUILD.gn +++ b/frameworks/libs/distributeddb/BUILD.gn @@ -117,6 +117,7 @@ ohos_shared_library("distributeddb") { "-Os", "-D_FORTIFY_SOURCE=2", "-flto", + "-Werror=vla", ] deps = [ "gaussdb_rd:gaussdb_rd" ] @@ -177,6 +178,7 @@ ohos_shared_library("customtokenizer") { "-fvisibility=hidden", "-Os", "-D_FORTIFY_SOURCE=2", + "-Werror=vla", ] external_deps = [ @@ -273,6 +275,7 @@ ohos_shared_library("distributeddb_client") { "-Os", "-D_FORTIFY_SOURCE=2", "-flto", + "-Werror=vla", ] external_deps = [ diff --git a/frameworks/libs/distributeddb/test/BUILD.gn b/frameworks/libs/distributeddb/test/BUILD.gn index 04111eb8335725aacdad5bec7891d9e965ec3621..03371310e15d9c446345fae89ed21db6ea1b4be0 100644 --- a/frameworks/libs/distributeddb/test/BUILD.gn +++ b/frameworks/libs/distributeddb/test/BUILD.gn @@ -990,7 +990,9 @@ ohos_unittest("tokenizer_test") { sources += [ "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/common/src/log_print.cpp" ] configs = [ ":tokenizer_config_unittest" ] - cflags_cc = [] + cflags_cc = [ + "-Werror=vla", + ] external_deps = [ "c_utils:utils", diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_async_download_assets_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_async_download_assets_test.cpp index d661f1adb631e0147fc155466051d8c90217e831..cfa51878e4f9f8366925a58fe3f654e65e7b37d5 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_async_download_assets_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_async_download_assets_test.cpp @@ -1023,17 +1023,16 @@ HWTEST_F(DistributedDBCloudAsyncDownloadAssetsTest, AsyncNormalDownload005, Test auto schema = GetSchema(); int threadNum = 10; CloudSyncOption option = GetAsyncCloudSyncOption(); - thread *syncThreads[threadNum]; + std::vector syncThreads; for (int i = 0; i < threadNum; i++) { - syncThreads[i] = new thread([&]() { + syncThreads.emplace_back([&]() { EXPECT_EQ(RDBDataGenerator::InsertCloudDBData(0, cloudCount, 0, schema, virtualCloudDb_), OK); RelationalTestUtils::CloudBlockSync(option, delegate_); DeleteLocalData(db_, "AsyncDownloadAssetsTest"); }); } for (auto &thread : syncThreads) { - thread->join(); - delete thread; + thread.join(); } auto manager = RuntimeContext::GetInstance()->GetAssetsDownloadManager(); ASSERT_NE(manager, nullptr);