From cf6c80839daa2d62d976ebc93dcde740c6e3afad Mon Sep 17 00:00:00 2001 From: zqq Date: Sat, 7 Mar 2026 11:50:22 +0800 Subject: [PATCH] add -Werror=vla Signed-off-by: zqq --- CMakeLists.txt | 2 +- frameworks/libs/distributeddb/BUILD.gn | 3 +++ frameworks/libs/distributeddb/test/BUILD.gn | 4 +++- .../distributeddb_cloud_async_download_assets_test.cpp | 7 +++---- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 35e4e8dad17..a61a37ae320 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 b85586a8d06..f288cc35f51 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 04111eb8335..03371310e15 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 d661f1adb63..cfa51878e4f 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); -- Gitee