diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index e3a1eebe895ca5d0647aaba9f40f5bc2f13e3400..c867a290ad300ccaf96b2fed631dbfc2ba1eb0e7 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 e5ff1bdb31cb0cc1608f2ffb5d8040c33b5158d9..0072026f44a272eaa050be112888e97f9085e2a8 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 719e76cc11c12e5e4f0c122e9d2ef2dee7a34aa8..4317c7cd395001dbd9d56b2a6340b1c170e37d57 100644 --- a/utils/src/report_data_callback.cpp +++ b/utils/src/report_data_callback.cpp @@ -59,7 +59,9 @@ 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; + if (event->data != nullptr) { + delete[] event->data; + } return ERROR; } int32_t leftSize = CIRCULAR_BUF_LEN - cb->eventsBuf_.eventNum;