From 03253e50b1384a4064ade65067bc916403b8aba3 Mon Sep 17 00:00:00 2001 From: mrsongliang Date: Mon, 18 Dec 2023 03:16:17 +0000 Subject: [PATCH 1/2] Signed-off-by:mrsongliang Signed-off-by: mrsongliang Change-Id: Iae73f0290f118d43d2475333a4075fe3b7941f46 --- .../cooperate/src/js_cooperate_context.cpp | 20 +++++++++---------- .../src/js_coordination_context.cpp | 2 +- frameworks/js/napi/src/devicestatus_napi.cpp | 20 +++++++++---------- frameworks/native/src/fd_listener.cpp | 2 +- .../server/src/cooperate_softbus_adapter.cpp | 2 +- libs/src/devicestatus_data_parse.cpp | 4 ++-- .../src/device_status_algorithm_test.cpp | 2 +- .../unittest/src/device_status_mock_test.cpp | 2 +- .../src/coordination_softbus_adapter.cpp | 8 ++++---- services/native/src/devicestatus_dumper.cpp | 2 +- .../src/devicestatus_msdp_client_impl.cpp | 4 ++-- services/native/src/stream_server.cpp | 2 +- utils/common/src/util.cpp | 6 +++--- 13 files changed, 38 insertions(+), 38 deletions(-) diff --git a/frameworks/js/napi/interaction/cooperate/src/js_cooperate_context.cpp b/frameworks/js/napi/interaction/cooperate/src/js_cooperate_context.cpp index 49453f603..03cf51dd1 100644 --- a/frameworks/js/napi/interaction/cooperate/src/js_cooperate_context.cpp +++ b/frameworks/js/napi/interaction/cooperate/src/js_cooperate_context.cpp @@ -59,7 +59,7 @@ napi_value JsCooperateContext::Enable(napi_env env, napi_callback_info info) { CALL_INFO_TRACE; size_t argc = TWO_PARAM; - napi_value argv[TWO_PARAM] = {}; + napi_value argv[TWO_PARAM] = { nullptr }; CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc == ZERO_PARAM) { @@ -91,7 +91,7 @@ napi_value JsCooperateContext::Start(napi_env env, napi_callback_info info) { CALL_INFO_TRACE; size_t argc = THREE_PARAM; - napi_value argv[THREE_PARAM] = {}; + napi_value argv[THREE_PARAM] = { nullptr }; CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc < TWO_PARAM) { @@ -106,7 +106,7 @@ napi_value JsCooperateContext::Start(napi_env env, napi_callback_info info) THROWERR(env, COMMON_PARAMETER_ERROR, "startDeviceId", "number"); return nullptr; } - char remoteNetworkDescriptor[MAX_STRING_LEN] = {}; + char remoteNetworkDescriptor[MAX_STRING_LEN] = { 0 }; int32_t startDeviceId = ZERO_PARAM; size_t length = ZERO_PARAM; CHKRP(napi_get_value_string_utf8(env, argv[ZERO_PARAM], remoteNetworkDescriptor, @@ -131,7 +131,7 @@ napi_value JsCooperateContext::Stop(napi_env env, napi_callback_info info) { CALL_INFO_TRACE; size_t argc = ONE_PARAM; - napi_value argv[ONE_PARAM] = {}; + napi_value argv[ONE_PARAM] = { nullptr }; CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); JsCooperateContext *jsDev = JsCooperateContext::GetInstance(env); @@ -152,7 +152,7 @@ napi_value JsCooperateContext::GetState(napi_env env, napi_callback_info info) { CALL_INFO_TRACE; size_t argc = TWO_PARAM; - napi_value argv[TWO_PARAM] = {}; + napi_value argv[TWO_PARAM] = { nullptr }; CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc == ZERO_PARAM) { @@ -186,7 +186,7 @@ napi_value JsCooperateContext::GetState(napi_env env, napi_callback_info info) napi_value JsCooperateContext::On(napi_env env, napi_callback_info info) { CALL_INFO_TRACE; - napi_value argv[TWO_PARAM] = {}; + napi_value argv[TWO_PARAM] = { nullptr }; size_t argc = TWO_PARAM; CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc == ZERO_PARAM) { @@ -198,7 +198,7 @@ napi_value JsCooperateContext::On(napi_env env, napi_callback_info info) THROWERR(env, COMMON_PARAMETER_ERROR, "type", "string"); return nullptr; } - char type[MAX_STRING_LEN] = {}; + char type[MAX_STRING_LEN] = { 0 }; size_t length = ZERO_PARAM; CHKRP(napi_get_value_string_utf8(env, argv[ZERO_PARAM], type, sizeof(type), &length), GET_VALUE_STRING_UTF8); if (std::strcmp(type, "cooperation") != ZERO_PARAM) { @@ -221,7 +221,7 @@ napi_value JsCooperateContext::Off(napi_env env, napi_callback_info info) { CALL_INFO_TRACE; size_t argc = TWO_PARAM; - napi_value argv[TWO_PARAM] = {}; + napi_value argv[TWO_PARAM] = { nullptr }; CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc == ZERO_PARAM) { @@ -232,7 +232,7 @@ napi_value JsCooperateContext::Off(napi_env env, napi_callback_info info) THROWERR(env, COMMON_PARAMETER_ERROR, "type", "string"); return nullptr; } - char type[MAX_STRING_LEN] = {}; + char type[MAX_STRING_LEN] = { 0 }; size_t length = ZERO_PARAM; CHKRP(napi_get_value_string_utf8(env, argv[ZERO_PARAM], type, sizeof(type), &length), GET_VALUE_STRING_UTF8); std::string typeTmp = type; @@ -403,7 +403,7 @@ void JsCooperateContext::DeclareDeviceCoordinationData(napi_env env, napi_value napi_value JsCooperateContext::EnumClassConstructor(napi_env env, napi_callback_info info) { size_t argc = ZERO_PARAM; - napi_value args[ONE_PARAM] = {}; + napi_value args[ONE_PARAM] = { nullptr }; napi_value result = nullptr; void *data = nullptr; CHKRP(napi_get_cb_info(env, info, &argc, args, &result, &data), GET_CB_INFO); diff --git a/frameworks/js/napi/interaction/coordination/src/js_coordination_context.cpp b/frameworks/js/napi/interaction/coordination/src/js_coordination_context.cpp index 23ba8efe5..3b8f8e4d1 100644 --- a/frameworks/js/napi/interaction/coordination/src/js_coordination_context.cpp +++ b/frameworks/js/napi/interaction/coordination/src/js_coordination_context.cpp @@ -548,7 +548,7 @@ void JsCoordinationContext::DeclareDeviceCoordinationInterface(napi_env env, nap napi_value JsCoordinationContext::EnumClassConstructor(napi_env env, napi_callback_info info) { size_t argc = 0; - napi_value args[1] = {}; + napi_value args[1] = { nullptr }; napi_value result = nullptr; void *data = nullptr; CHKRP(napi_get_cb_info(env, info, &argc, args, &result, &data), GET_CB_INFO); diff --git a/frameworks/js/napi/src/devicestatus_napi.cpp b/frameworks/js/napi/src/devicestatus_napi.cpp index 2d610b2e1..30baaa297 100644 --- a/frameworks/js/napi/src/devicestatus_napi.cpp +++ b/frameworks/js/napi/src/devicestatus_napi.cpp @@ -137,9 +137,9 @@ int32_t DeviceStatusNapi::ConvertTypeToInt(const std::string &type) bool DeviceStatusNapi::CheckArguments(napi_env env, napi_callback_info info) { CALL_DEBUG_ENTER; - int32_t arr[ARG_4] = {}; + int32_t arr[ARG_4] = { 0 }; size_t argc = ARG_4; - napi_value args[ARG_4] = {}; + napi_value args[ARG_4] = { nullptr }; napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); if (status != napi_ok) { FI_HILOGE("Failed to get_cb_info"); @@ -178,9 +178,9 @@ bool DeviceStatusNapi::IsMatchType(napi_env env, napi_value value, napi_valuetyp bool DeviceStatusNapi::CheckGetArguments(napi_env env, napi_callback_info info) { CALL_DEBUG_ENTER; - int32_t arr[ARG_2] = {}; + int32_t arr[ARG_2] = { 0 }; size_t argc = ARG_2; - napi_value args[ARG_2] = {}; + napi_value args[ARG_2] = { nullptr }; napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); if (status != napi_ok) { FI_HILOGE("Failed to get_cb_info"); @@ -208,7 +208,7 @@ std::tuple DeviceStatusNapi::Ch { std::tuple result { false, nullptr, "", -1, -1 }; size_t argc = ARG_4; - napi_value args[ARG_4] = {}; + napi_value args[ARG_4] = { nullptr }; napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); if ((status != napi_ok) || (argc < ARG_4)) { ThrowErr(env, PARAM_ERROR, "Bad parameters"); @@ -224,7 +224,7 @@ std::tuple DeviceStatusNapi::Ch ThrowErr(env, PARAM_ERROR, "Failed to get string item"); return result; } - char mode[NAPI_BUF_LENGTH] = {}; + char mode[NAPI_BUF_LENGTH] = { 0 }; status = napi_get_value_string_utf8(env, args[ARG_0], mode, modLen + 1, &modLen); if (status != napi_ok) { ThrowErr(env, PARAM_ERROR, "Failed to get mode"); @@ -249,7 +249,7 @@ std::tuple DeviceStatusNapi::CheckGetParam(napi_env e { std::tuple result { false, nullptr, -1 }; size_t argc = ARG_2; - napi_value args[ARG_2] = {}; + napi_value args[ARG_2] = { nullptr }; napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); if ((status != napi_ok) || (argc < ARG_2)) { ThrowErr(env, PARAM_ERROR, "Bad parameters"); @@ -265,7 +265,7 @@ std::tuple DeviceStatusNapi::CheckGetParam(napi_env e ThrowErr(env, PARAM_ERROR, "Failed to get string item"); return result; } - char mode[NAPI_BUF_LENGTH] = {}; + char mode[NAPI_BUF_LENGTH] = { 0 }; napiStatus = napi_get_value_string_utf8(env, args[ARG_0], mode, modLen + 1, &modLen); if (napiStatus != napi_ok) { ThrowErr(env, PARAM_ERROR, "Failed to get mode"); @@ -288,7 +288,7 @@ napi_value DeviceStatusNapi::GetParameters(napi_env env, size_t argc, const napi ThrowErr(env, PARAM_ERROR, "Failed to get string item"); return nullptr; } - char mode[NAPI_BUF_LENGTH] = {}; + char mode[NAPI_BUF_LENGTH] = { 0 }; status = napi_get_value_string_utf8(env, args[0], mode, modLen + 1, &modLen); if (status != napi_ok) { ThrowErr(env, PARAM_ERROR, "Failed to get mode"); @@ -401,7 +401,7 @@ napi_value DeviceStatusNapi::UnsubscribeDeviceStatus(napi_env env, napi_callback CALL_DEBUG_ENTER; CHKPP(g_obj); size_t argc = 3; - napi_value args[3] = {}; + napi_value args[3] = { nullptr }; napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); if (status != napi_ok) { ThrowErr(env, PARAM_ERROR, "Bad parameters"); diff --git a/frameworks/native/src/fd_listener.cpp b/frameworks/native/src/fd_listener.cpp index 72f0a4702..461138f3f 100644 --- a/frameworks/native/src/fd_listener.cpp +++ b/frameworks/native/src/fd_listener.cpp @@ -37,7 +37,7 @@ void FdListener::OnReadable(int32_t fd) return; } CHKPV(iClient_); - char szBuf[MAX_PACKET_BUF_SIZE] = {}; + char szBuf[MAX_PACKET_BUF_SIZE] = { 0 }; for (int32_t i = 0; i < MAX_RECV_LIMIT; i++) { ssize_t size = recv(fd, szBuf, MAX_PACKET_BUF_SIZE, MSG_DONTWAIT | MSG_NOSIGNAL); if (size > 0) { diff --git a/intention/cooperate/server/src/cooperate_softbus_adapter.cpp b/intention/cooperate/server/src/cooperate_softbus_adapter.cpp index 9e92d34ea..80758fb51 100644 --- a/intention/cooperate/server/src/cooperate_softbus_adapter.cpp +++ b/intention/cooperate/server/src/cooperate_softbus_adapter.cpp @@ -567,7 +567,7 @@ std::string CooperateSoftbusAdapter::FindDevice(int32_t sessionId) int32_t CooperateSoftbusAdapter::OnSessionOpened(int32_t sessionId, int32_t result) { CALL_INFO_TRACE; - char peerDevId[DEVICE_ID_SIZE_MAX] = {}; + char peerDevId[DEVICE_ID_SIZE_MAX] = { 0 }; sessionId_ = sessionId; int32_t getPeerDeviceIdResult = GetPeerDeviceId(sessionId, peerDevId, sizeof(peerDevId)); FI_HILOGD("Get peer device id ret:%{public}d", getPeerDeviceIdResult); diff --git a/libs/src/devicestatus_data_parse.cpp b/libs/src/devicestatus_data_parse.cpp index e736b026c..d0cba852d 100644 --- a/libs/src/devicestatus_data_parse.cpp +++ b/libs/src/devicestatus_data_parse.cpp @@ -130,7 +130,7 @@ std::string DeviceStatusDataParse::ReadJsonFile(const std::string &filePath) FI_HILOGE("Path is empty"); return {}; } - char realPath[PATH_MAX] = {}; + char realPath[PATH_MAX] = { 0 }; if (realpath(filePath.c_str(), realPath) == nullptr) { FI_HILOGE("Path is error, %{public}d", errno); return {}; @@ -192,7 +192,7 @@ std::string DeviceStatusDataParse::ReadFile(const std::string &filePath) return {}; } std::string dataStr; - char buf[READ_DATA_BUFF_SIZE] = {}; + char buf[READ_DATA_BUFF_SIZE] = { 0 }; while (fgets(buf, sizeof(buf), fp) != nullptr) { dataStr += buf; } diff --git a/libs/test/unittest/src/device_status_algorithm_test.cpp b/libs/test/unittest/src/device_status_algorithm_test.cpp index f40feeacb..4678ed2b7 100644 --- a/libs/test/unittest/src/device_status_algorithm_test.cpp +++ b/libs/test/unittest/src/device_status_algorithm_test.cpp @@ -85,7 +85,7 @@ int32_t DeviceStatusAlgorithmTest::LoadAlgoLibrary(const std::shared_ptr 0) { diff --git a/utils/common/src/util.cpp b/utils/common/src/util.cpp index ff91650be..f92f6ea0c 100644 --- a/utils/common/src/util.cpp +++ b/utils/common/src/util.cpp @@ -54,7 +54,7 @@ static std::string GetThisThreadIdOfString() thread_local std::string threadLocalId; if (threadLocalId.empty()) { long tid = syscall(SYS_gettid); - char buf[BUF_TID_SIZE] = {}; + char buf[BUF_TID_SIZE] = { 0 }; const int32_t ret = sprintf_s(buf, BUF_TID_SIZE, "%06d", tid); if (ret < 0) { FI_HILOGE("Call sprintf_s failed, ret:%{public}d", ret); @@ -189,7 +189,7 @@ static std::string GetFileName(const std::string &path) const char* GetProgramName() { - static char programName[PROGRAM_NAME_SIZE] = {}; + static char programName[PROGRAM_NAME_SIZE] = { 0 }; if (programName[0] != '\0') { return programName; } @@ -268,7 +268,7 @@ bool IsValidSvgFile(const std::string &filePath) FI_HILOGE("FilePath is empty"); return false; } - char realPath[PATH_MAX] = {}; + char realPath[PATH_MAX] = { 0 }; if (realpath(filePath.c_str(), realPath) == nullptr) { FI_HILOGE("Realpath return nullptr, realPath:%{public}s", realPath); return false; From 92a4c8e7ee3af5fe01ad1e10e378a669240bea7b Mon Sep 17 00:00:00 2001 From: mrsongliang Date: Tue, 19 Dec 2023 01:44:55 +0000 Subject: [PATCH 2/2] Signed-off-by:mrsongliang Signed-off-by: mrsongliang Change-Id: Id91b8d322c688cdfda69e965f199c20f29253c55 --- frameworks/js/napi/interaction/drag/src/js_drag_manager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/js/napi/interaction/drag/src/js_drag_manager.cpp b/frameworks/js/napi/interaction/drag/src/js_drag_manager.cpp index a438112aa..c55108ee6 100644 --- a/frameworks/js/napi/interaction/drag/src/js_drag_manager.cpp +++ b/frameworks/js/napi/interaction/drag/src/js_drag_manager.cpp @@ -51,13 +51,13 @@ bool JsDragManager::IsSameHandle(napi_env env, napi_value handle, napi_ref ref) napi_value JsDragManager::GetDataSummary(napi_env env) { CALL_INFO_TRACE; + napi_value arr = nullptr; + CHKRP(napi_create_array(env, &arr), CREATE_ARRAY); std::map summarys; if (INTERACTION_MGR->GetDragSummary(summarys) != RET_OK) { FI_HILOGE("Failed to GetDragSummary"); - return nullptr; + return arr; } - napi_value arr = nullptr; - CHKRP(napi_create_array(env, &arr), CREATE_ARRAY); uint32_t index = 0; for (const auto &summary : summarys) { napi_value dataType = nullptr;