From 2018829b5a1c10324f44d113303814961aad9588 Mon Sep 17 00:00:00 2001 From: puhui Date: Tue, 8 Mar 2022 21:45:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4codex=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: puhui --- .../native_cpp/src/device_manager_impl.cpp | 9 ++++++--- .../kits/js/src/native_devicemanager_js.cpp | 5 ++--- .../src/authentication/dm_auth_manager.cpp | 2 +- .../src/dependency/timer/dm_timer.cpp | 5 ----- .../src/ipc/standard/ipc_cmd_parser.cpp | 2 +- .../src/ipc/standard/ipc_server_stub.cpp | 15 ++++++++++----- utils/src/dm_anonymous.cpp | 4 ++-- 7 files changed, 22 insertions(+), 20 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index e861dbca4..91fd9fbe7 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -273,17 +273,20 @@ int32_t DeviceManagerImpl::UnAuthenticateDevice(const std::string &pkgName, cons } DmDeviceInfo deviceInfo; - strcpy_s(deviceInfo.deviceId, DM_MAX_DEVICE_ID_LEN, deviceId.c_str()); + int32_t ret = strcpy_s(deviceInfo.deviceId, DM_MAX_DEVICE_ID_LEN, deviceId.c_str()); + if (ret != DM_OK) { + LOGE("UnAuthenticateDevice error: copy deviceId failed"); + return DM_INVALID_VALUE; + } std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); req->SetDeviceInfo(deviceInfo); - int32_t ret = ipcClientProxy_->SendRequest(UNAUTHENTICATE_DEVICE, req, rsp); + ret = ipcClientProxy_->SendRequest(UNAUTHENTICATE_DEVICE, req, rsp); if (ret != DM_OK) { LOGE("UnAuthenticateDevice error: Send Request failed ret: %d", ret); return DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); if (ret != DM_OK) { LOGE("UnAuthenticateDevice error: Failed with ret %d", ret); diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index b6cec4792..215a2cd20 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -1078,11 +1078,10 @@ void DeviceManagerNapi::CallGetTrustedDeviceListStatus(napi_env env, napi_status bool isArray = false; napi_create_array(env, &array[1]); napi_is_array(env, array[1], &isArray); - if (isArray == false) { + if (!isArray) { LOGE("napi_create_array fail"); } - - for (int32_t i = 0; i != deviceInfoListAsyncCallbackInfo->devList.size(); ++i) { + for (size_t i = 0; i != deviceInfoListAsyncCallbackInfo->devList.size(); ++i) { DeviceInfoToJsArray(env, deviceInfoListAsyncCallbackInfo->devList, i, array[1]); } LOGE("devList is OK"); diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index 359721a01..eeb032229 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -414,7 +414,7 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); bool ret = hiChainConnector_->IsDevicesInGroup(authResponseContext_->localDeviceId, localDeviceId); - if (ret != true) { + if (!ret) { LOGE("DmAuthManager::EstablishAuthChannel device is in group"); authResponseContext_->reply = DM_AUTH_PEER_REJECT; } else { diff --git a/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp b/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp index 897800efe..9ef388b1c 100644 --- a/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp +++ b/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp @@ -73,7 +73,6 @@ DmTimerStatus DmTimer::Start(uint32_t timeOut, TimeoutHandle handle, void *data) mStatus_ = DmTimerStatus::DM_STATUS_RUNNING; mThread_ = std::thread(&DmTimer::WaitForTimeout, this); mThread_.detach(); - return mStatus_; } @@ -87,12 +86,9 @@ void DmTimer::Stop(int32_t code) if (mTimeFd_[1]) { char event = 'S'; if (write(mTimeFd_[1], &event, 1) < 0) { - LOGE("DmTimer %s Stop timer failed, errno %d", mTimerName_.c_str(), errno); return; } - LOGI("DmTimer %s Stop success", mTimerName_.c_str()); } - return; } void DmTimer::WaitForTimeout() @@ -122,7 +118,6 @@ void DmTimer::WaitForTimeout() Release(); LOGE("DmTimer %s end timer at (%d)s", mTimerName_.c_str(), mTimeOutSec_); } - return; } int32_t DmTimer::CreateTimeFd() diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp index fc4807ccb..42654f175 100644 --- a/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp @@ -394,7 +394,7 @@ ON_IPC_CMD(SERVER_GET_DMFA_INFO, MessageParcel &data, MessageParcel &reply) int32_t ret = DM_OK; ret = DeviceManagerService::GetInstance().GetFaParam(packName, authParam); int32_t appIconLen = authParam.imageinfo.GetAppIconLen(); - uint32_t appThumbnailLen = authParam.imageinfo.GetAppThumbnailLen(); + int32_t appThumbnailLen = authParam.imageinfo.GetAppThumbnailLen(); if (!reply.WriteInt32(authParam.direction) || !reply.WriteInt32(authParam.authType) || !reply.WriteString(authParam.authToken) || !reply.WriteString(authParam.packageName) || diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp index 71b0bbabf..30f37fc6b 100644 --- a/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp +++ b/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp @@ -133,12 +133,17 @@ int32_t IpcServerStub::RegisterDeviceManagerListener(std::string &pkgName, sptr< LOGI("RegisterDeviceManagerListener: listener already exists"); return DM_OK; } - sptr appRecipient = sptr(new AppDeathRecipient()); - if (!listener->AddDeathRecipient(appRecipient)) { - LOGE("RegisterDeviceManagerListener: AddDeathRecipient Failed"); + try { + sptr appRecipient = sptr(new AppDeathRecipient()); + if (!listener->AddDeathRecipient(appRecipient)) { + LOGE("RegisterDeviceManagerListener: AddDeathRecipient Failed"); + } + dmListener_[pkgName] = listener; + appRecipient_[pkgName] = appRecipient; + } catch (const std::bad_alloc &e) { + LOGE("new AppDeathRecipient failed"); + return DM_MALLOC_ERROR; } - dmListener_[pkgName] = listener; - appRecipient_[pkgName] = appRecipient; return DM_OK; } diff --git a/utils/src/dm_anonymous.cpp b/utils/src/dm_anonymous.cpp index 907c9f208..8fbe5b580 100644 --- a/utils/src/dm_anonymous.cpp +++ b/utils/src/dm_anonymous.cpp @@ -24,7 +24,7 @@ std::string GetAnonyString(const std::string &value) const int32_t INT32_MIN_ID_LENGTH = 3; std::string tmpStr("******"); - int32_t strLen = value.length(); + size_t strLen = value.length(); if (strLen < INT32_MIN_ID_LENGTH) { return tmpStr; } @@ -46,7 +46,7 @@ std::string GetAnonyString(const std::string &value) std::string GetAnonyInt32(const int32_t value) { std::string tempString = std::to_string(value); - int32_t length = tempString.length(); + size_t length = tempString.length(); if (length == 0x01) { tempString[0] = '*'; return tempString; -- Gitee