From ad1dd6d2c779f561ec89c40110c57073eabce396 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Tue, 15 Mar 2022 16:04:05 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- frameworks/native/sensor/src/sensor_agent_proxy.cpp | 3 ++- services/sensor/src/sensor_service.cpp | 4 ++-- utils/src/report_data_callback.cpp | 6 ++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index e3a1eebe..c867a290 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -178,7 +178,7 @@ int32_t SensorAgentProxy::ActivateSensor(int32_t sensorId, const SensorUser *use return OHOS::Sensors::ERROR; } std::lock_guard subscribeLock(subscribeMutex_); - if ((g_subscribeMap.find(sensorId) == g_subscribeMap.end()) || (g_subscribeMap.at(sensorId) != user)) { + if ((g_subscribeMap.find(sensorId) == g_subscribeMap.end()) || (g_subscribeMap[sensorId] != user)) { HiLog::Error(LABEL, "%{public}s subscribe sensorId first", __func__); return OHOS::Sensors::ERROR; } @@ -189,6 +189,7 @@ int32_t SensorAgentProxy::ActivateSensor(int32_t sensorId, const SensorUser *use if (ret != 0) { HiLog::Error(LABEL, "%{public}s enable sensor failed, ret: %{public}d", __func__, ret); g_subscribeMap.erase(sensorId); + return OHOS::Sensors::ERROR; } return OHOS::Sensors::SUCCESS; diff --git a/services/sensor/src/sensor_service.cpp b/services/sensor/src/sensor_service.cpp index e5ff1bdb..0072026f 100644 --- a/services/sensor/src/sensor_service.cpp +++ b/services/sensor/src/sensor_service.cpp @@ -158,11 +158,11 @@ void SensorService::OnStop() void SensorService::ReportSensorUsedInfo(uint32_t sensorId, bool enable) { - char uidChar[REPORT_STATUS_LEN]; + char uidChar[REPORT_STATUS_LEN] = {0}; int32_t uid = this->GetCallingUid(); std::string packageName(""); sensorManager_.GetPackageNameFromUid(uid, packageName); - int32_t ret = sprintf_s(uidChar, sizeof(uidChar), "%d", uid); + int32_t ret = sprintf_s(uidChar, sizeof(uidChar) - 1, "%d", uid); if (ret < 0) { HiLog::Error(LABEL, "%{public}s sprintf uidChar failed", __func__); return; diff --git a/utils/src/report_data_callback.cpp b/utils/src/report_data_callback.cpp index 719e76cc..5afd0320 100644 --- a/utils/src/report_data_callback.cpp +++ b/utils/src/report_data_callback.cpp @@ -59,8 +59,10 @@ int32_t ReportDataCallback::ZReportDataCallback(const struct SensorEvent* event, } if (cb == nullptr || cb->eventsBuf_.circularBuf == nullptr) { HiLog::Error(LABEL, "%{public}s callback or circularBuf or event cannot be null", __func__); - delete[] event->data; - return ERROR; + if (event->data == nullptr) { + delete[] event->data; + return ERROR; + } } int32_t leftSize = CIRCULAR_BUF_LEN - cb->eventsBuf_.eventNum; int32_t toEndLen = CIRCULAR_BUF_LEN - cb->eventsBuf_.writePosition; -- Gitee From 2cebcd09d6b820523a16879445dbe60b4889cba2 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Tue, 15 Mar 2022 19:53:28 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- utils/src/report_data_callback.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils/src/report_data_callback.cpp b/utils/src/report_data_callback.cpp index 5afd0320..043bb268 100644 --- a/utils/src/report_data_callback.cpp +++ b/utils/src/report_data_callback.cpp @@ -59,11 +59,10 @@ int32_t ReportDataCallback::ZReportDataCallback(const struct SensorEvent* event, } if (cb == nullptr || cb->eventsBuf_.circularBuf == nullptr) { HiLog::Error(LABEL, "%{public}s callback or circularBuf or event cannot be null", __func__); - if (event->data == nullptr) { + if (event->data != nullptr) delete[] event->data; return ERROR; } - } int32_t leftSize = CIRCULAR_BUF_LEN - cb->eventsBuf_.eventNum; int32_t toEndLen = CIRCULAR_BUF_LEN - cb->eventsBuf_.writePosition; if (toEndLen == 0) { -- Gitee From 6786636f5ec6572d18bb67f39e469595acdbc647 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Tue, 15 Mar 2022 21:04:17 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- utils/src/report_data_callback.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/utils/src/report_data_callback.cpp b/utils/src/report_data_callback.cpp index 043bb268..4317c7cd 100644 --- a/utils/src/report_data_callback.cpp +++ b/utils/src/report_data_callback.cpp @@ -59,10 +59,11 @@ int32_t ReportDataCallback::ZReportDataCallback(const struct SensorEvent* event, } if (cb == nullptr || cb->eventsBuf_.circularBuf == nullptr) { HiLog::Error(LABEL, "%{public}s callback or circularBuf or event cannot be null", __func__); - if (event->data != nullptr) + if (event->data != nullptr) { delete[] event->data; - return ERROR; } + return ERROR; + } int32_t leftSize = CIRCULAR_BUF_LEN - cb->eventsBuf_.eventNum; int32_t toEndLen = CIRCULAR_BUF_LEN - cb->eventsBuf_.writePosition; if (toEndLen == 0) { -- Gitee