diff --git a/frameworks/js/napi/user_auth/src/user_auth_entry.cpp b/frameworks/js/napi/user_auth/src/user_auth_entry.cpp index 8f5d0c963..70e757092 100644 --- a/frameworks/js/napi/user_auth/src/user_auth_entry.cpp +++ b/frameworks/js/napi/user_auth/src/user_auth_entry.cpp @@ -254,7 +254,7 @@ napi_status UnwrapAuthInstanceV10(napi_env env, napi_callback_info info, UserAut return ret; } if (*authInstanceV10 == nullptr) { - IAM_LOGE("authInstanceV9 is null"); + IAM_LOGE("authInstanceV10 is null"); return napi_generic_failure; } return ret; diff --git a/frameworks/js/napi/user_auth/src/user_auth_instance_v10.cpp b/frameworks/js/napi/user_auth/src/user_auth_instance_v10.cpp index 253918e40..e56259250 100644 --- a/frameworks/js/napi/user_auth/src/user_auth_instance_v10.cpp +++ b/frameworks/js/napi/user_auth/src/user_auth_instance_v10.cpp @@ -334,8 +334,8 @@ UserAuthResultCode UserAuthInstanceV10::InitWidgetParam(napi_env env, napi_value return UserAuthNapiHelper::ThrowErrorMsg(env, UserAuthResultCode::OHOS_INVALID_PARAM, msgStr); } std::string title = UserAuthNapiHelper::GetStringPropertyUtf8(env, value, WIDGET_PARAM_TITLE); - if (title == "" || title.length() > WidgetType::TITLE_MAX) { - IAM_LOGE("title is invalid. size: %{public}zu", title.length()); + if (title == "" || title.size() > WidgetType::TITLE_MAX) { + IAM_LOGE("title is invalid. size: %{public}zu", title.size()); std::string msgStr = "Parameter error. The length of \"title\" connot exceed 500."; return UserAuthNapiHelper::ThrowErrorMsg(env, UserAuthResultCode::OHOS_INVALID_PARAM, msgStr); } @@ -343,8 +343,8 @@ UserAuthResultCode UserAuthInstanceV10::InitWidgetParam(napi_env env, napi_value if (UserAuthNapiHelper::HasNamedProperty(env, value, WIDGET_PARAM_NAVIBTNTEXT)) { std::string naviBtnTxt = UserAuthNapiHelper::GetStringPropertyUtf8(env, value, WIDGET_PARAM_NAVIBTNTEXT); - if (naviBtnTxt == "" || naviBtnTxt.length() > WidgetType::BUTTON_MAX) { - IAM_LOGE("navigation button text is invalid, size: %{public}zu", naviBtnTxt.length()); + if (naviBtnTxt == "" || naviBtnTxt.size() > WidgetType::BUTTON_MAX) { + IAM_LOGE("navigation button text is invalid, size: %{public}zu", naviBtnTxt.size()); std::string msgStr = "Parameter error. The length of \"navigationButtonText\" connot exceed 60."; return UserAuthNapiHelper::ThrowErrorMsg(env, UserAuthResultCode::OHOS_INVALID_PARAM, msgStr); } diff --git a/frameworks/js/napi/user_auth/src/user_auth_napi_helper.cpp b/frameworks/js/napi/user_auth/src/user_auth_napi_helper.cpp index 816ffa0c1..aac2421f6 100644 --- a/frameworks/js/napi/user_auth/src/user_auth_napi_helper.cpp +++ b/frameworks/js/napi/user_auth/src/user_auth_napi_helper.cpp @@ -325,7 +325,7 @@ napi_status UserAuthNapiHelper::GetStrValue(napi_env env, napi_value value, char if (result != napi_ok) { IAM_LOGE("napi_get_value_string_utf8 fail"); } - if (out != nullptr && maxLen > 0) { + if (maxLen > 0) { out[maxLen - 1] = '\0'; } return result; diff --git a/frameworks/native/common/attributes/src/attributes.cpp b/frameworks/native/common/attributes/src/attributes.cpp index 3ee9f5b02..a8939c0cd 100644 --- a/frameworks/native/common/attributes/src/attributes.cpp +++ b/frameworks/native/common/attributes/src/attributes.cpp @@ -955,9 +955,7 @@ bool Attributes::Impl::DecodeStringValue(const std::vector &src, std::s return false; } - std::string out(static_cast(static_cast(src.data()))); - - dst.swap(out); + dst.assign(src.begin(), src.end() -1); return true; } diff --git a/frameworks/native/ipc/src/user_auth_proxy.cpp b/frameworks/native/ipc/src/user_auth_proxy.cpp index de3274e17..896d1bf6c 100644 --- a/frameworks/native/ipc/src/user_auth_proxy.cpp +++ b/frameworks/native/ipc/src/user_auth_proxy.cpp @@ -193,7 +193,7 @@ void UserAuthProxy::SetProperty(int32_t userId, AuthType authType, const Attribu bool UserAuthProxy::WriteAuthParam(MessageParcel &data, const AuthParamInner &authParam) { if (!data.WriteInt32(authParam.userId)) { - IAM_LOGE("failed to write authType"); + IAM_LOGE("failed to write userId"); return false; } if (!data.WriteUInt8Vector(authParam.challenge)) { diff --git a/frameworks/native/ipc/src/user_auth_stub.cpp b/frameworks/native/ipc/src/user_auth_stub.cpp index e2626236a..9615dc5fb 100644 --- a/frameworks/native/ipc/src/user_auth_stub.cpp +++ b/frameworks/native/ipc/src/user_auth_stub.cpp @@ -353,11 +353,11 @@ bool UserAuthStub::ReadWidgetParam(MessageParcel &data, WidgetParam &widgetParam { if (!data.ReadString(widgetParam.title)) { IAM_LOGE("failed to read title"); - return READ_PARCEL_ERROR; + return false; } if (!data.ReadString(widgetParam.navigationButtonText)) { IAM_LOGE("failed to read navigationButtonText"); - return READ_PARCEL_ERROR; + return false; } int32_t winMode; if (!data.ReadInt32(winMode)) { @@ -493,7 +493,11 @@ int32_t UserAuthStub::NoticeStub(MessageParcel &data, MessageParcel &reply) IAM_LOGE("NoticeStub unsupport notice type"); return ResultCode::GENERAL_ERROR; } - std::string eventData = data.ReadString(); + std::string eventData; + if (!data.ReadString(eventData)) { + IAM_LOGE("failed to read eventData"); + return ResultCode::READ_PARCEL_ERROR; + } int32_t result = Notice(noticeType, eventData); if (!reply.WriteInt32(result)) { @@ -664,7 +668,7 @@ int32_t UserAuthStub::SetGlobalConfigParamStub(MessageParcel &data, MessageParce return ret; } if (!data.ReadInt32Vector(&globalConfigParam.userIds)) { - IAM_LOGE("failed to write userIds"); + IAM_LOGE("failed to read userIds"); return READ_PARCEL_ERROR; } std::vector authTypeList; diff --git a/services/context/src/remote_auth_service.cpp b/services/context/src/remote_auth_service.cpp index 53ac491e9..55d23657b 100644 --- a/services/context/src/remote_auth_service.cpp +++ b/services/context/src/remote_auth_service.cpp @@ -26,7 +26,6 @@ #include "context_pool.h" #include "device_manager_util.h" #include "hdi_wrapper.h" -#include "iam_para2str.h" #include "remote_executor_stub.h" #include "remote_iam_callback.h" #include "remote_msg_util.h" diff --git a/services/core/src/publish_event_adapter.cpp b/services/core/src/publish_event_adapter.cpp index 3f78b9955..e78b67ab1 100644 --- a/services/core/src/publish_event_adapter.cpp +++ b/services/core/src/publish_event_adapter.cpp @@ -38,9 +38,7 @@ const std::string USERIAM_COMMON_EVENT_SAMGR_PERMISSION = "ohos.permission.INTER void PublishEvent(EventFwk::CommonEventData data, const std::string &permission) { EventFwk::CommonEventPublishInfo publishInfo; - std::vector permissions; - permissions.push_back(permission); - publishInfo.SetSubscriberPermissions(permissions); + publishInfo.SetSubscriberPermissions({permission}); publishInfo.SetSticky(false); if (!EventFwk::CommonEventManager::PublishCommonEvent(data, publishInfo)) { IAM_LOGE("PublishCommonEvent failed, eventAction is %{public}s", data.GetWant().GetAction().c_str()); diff --git a/services/remote_connect/src/soft_bus_base_socket.cpp b/services/remote_connect/src/soft_bus_base_socket.cpp index 1d99ea2f0..9663ba2aa 100644 --- a/services/remote_connect/src/soft_bus_base_socket.cpp +++ b/services/remote_connect/src/soft_bus_base_socket.cpp @@ -219,7 +219,8 @@ ResultCode BaseSocket::SendRequest(const int32_t socketId, const std::string &co int32_t messageSeq = GetMessageSeq(); int32_t msgType = -1; - attributes->GetInt32Value(Attributes::ATTR_MSG_TYPE, msgType); + bool isGetVal = attributes->GetInt32Value(Attributes::ATTR_MSG_TYPE, msgType); + IF_FALSE_LOGE_AND_RETURN_VAL(isGetVal, INVALID_PARAMETERS); RefreshTraceInfo(connectionName, msgType, false, messageSeq); std::shared_ptr softBusMessage = Common::MakeShared(messageSeq, connectionName, srcEndPoint, destEndPoint, attributes); @@ -260,7 +261,8 @@ ResultCode BaseSocket::SendResponse(const int32_t socketId, const std::string &c IF_FALSE_LOGE_AND_RETURN_VAL(attributes != nullptr, INVALID_PARAMETERS); IF_FALSE_LOGE_AND_RETURN_VAL(socketId != INVALID_SOCKET_ID, INVALID_PARAMETERS); int32_t msgType = -1; - attributes->GetInt32Value(Attributes::ATTR_MSG_TYPE, msgType); + bool isGetVal = attributes->GetInt32Value(Attributes::ATTR_MSG_TYPE, msgType); + IF_FALSE_LOGE_AND_RETURN_VAL(isGetVal, INVALID_PARAMETERS); RefreshTraceInfo(connectionName, msgType, true, messageSeq); std::shared_ptr softBusMessage = Common::MakeShared(messageSeq, diff --git a/services/remote_connect/src/soft_bus_manager.cpp b/services/remote_connect/src/soft_bus_manager.cpp index 3d1efb530..a5b47c5cc 100644 --- a/services/remote_connect/src/soft_bus_manager.cpp +++ b/services/remote_connect/src/soft_bus_manager.cpp @@ -339,6 +339,7 @@ void SoftBusManager::ServiceSocketUnInit() std::vector socketIds; { std::lock_guard lock(softBusMutex_); + socketIds.reserve(socketMap_.size()); for (const auto &iter : socketMap_) { socketIds.push_back(iter.first); } diff --git a/test/unittest/services/src/soft_bus_base_socket_test.cpp b/test/unittest/services/src/soft_bus_base_socket_test.cpp index f523ae0f8..4d0560982 100644 --- a/test/unittest/services/src/soft_bus_base_socket_test.cpp +++ b/test/unittest/services/src/soft_bus_base_socket_test.cpp @@ -200,6 +200,7 @@ HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestSendRequest, TestSize.Level std::string destEndPoint = "456"; std::shared_ptr attributes = Common::MakeShared(); ASSERT_NE(attributes, nullptr); + attributes->SetInt32Value(Attributes::ATTR_MSG_TYPE, 1); MsgCallback callback; EXPECT_EQ(baseSocket->SendRequest(socketId, connectionName, srcEndPoint, destEndPoint, attributes, callback), GENERAL_ERROR); @@ -215,6 +216,7 @@ HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestSendResponse, TestSize.Leve std::string destEndPoint = "456"; std::shared_ptr attributes = Common::MakeShared(); ASSERT_NE(attributes, nullptr); + attributes->SetInt32Value(Attributes::ATTR_MSG_TYPE, 1); uint32_t messageSeq = 123; EXPECT_EQ(baseSocket->SendResponse(socketId, connectionName, srcEndPoint, destEndPoint, attributes, messageSeq), GENERAL_ERROR);