From 1a1311915f3ec6002c88be7bc2e9e01bc4110430 Mon Sep 17 00:00:00 2001 From: bailu1992 Date: Tue, 9 Jan 2024 19:58:27 +0800 Subject: [PATCH 1/3] =?UTF-8?q?sensor=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bailu1992 --- frameworks/native/src/native_sensor.cpp | 11 ++++++++--- frameworks/native/src/sensor_agent_proxy.cpp | 4 ++-- .../sensoragent_fuzzer/sensoragent_fuzzer.cpp | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/frameworks/native/src/native_sensor.cpp b/frameworks/native/src/native_sensor.cpp index f05eb049..bfcd647e 100644 --- a/frameworks/native/src/native_sensor.cpp +++ b/frameworks/native/src/native_sensor.cpp @@ -86,10 +86,15 @@ Sensor_Info **OH_Sensor_CreateInfos(uint32_t count) int32_t OH_Sensor_DestroyInfos(Sensor_Info **sensors, uint32_t count) { for (uint32_t i = 0; i < count; ++i) { - delete sensors[i]; + if (sensors[i] != nullptr) { + delete sensors[i]; + sensors[i] = nullptr; + } + } + if (sensors != nullptr) { + delete[] sensors; + sensors = nullptr; } - delete[] sensors; - sensors = nullptr; return SENSOR_SUCCESS; } diff --git a/frameworks/native/src/sensor_agent_proxy.cpp b/frameworks/native/src/sensor_agent_proxy.cpp index 14152488..eb6f3fdd 100644 --- a/frameworks/native/src/sensor_agent_proxy.cpp +++ b/frameworks/native/src/sensor_agent_proxy.cpp @@ -275,7 +275,7 @@ int32_t SensorAgentProxy::ConvertSensorInfos() const SEN_HILOGE("The number of sensors exceeds the maximum value"); return ERROR; } - sensorInfos_ = (SensorInfo *)malloc(sizeof(SensorInfo) * count); + sensorInfos_ = static_cast(malloc(sizeof(SensorInfo) * count)); CHKPR(sensorInfos_, ERROR); for (size_t i = 0; i < count; ++i) { SensorInfo *sensorInfo = sensorInfos_ + i; @@ -382,7 +382,7 @@ int32_t SensorAgentProxy::GetSensorActiveInfos(int32_t pid, SEN_HILOGE("The number of active info exceeds the maximum value, count:%{public}zu", activeInfoCount); return ERROR; } - sensorActiveInfos_ = (SensorActiveInfo *)malloc(sizeof(SensorActiveInfo) * activeInfoCount); + sensorActiveInfos_ = static_cast(malloc(sizeof(SensorActiveInfo) * activeInfoCount)); CHKPR(sensorActiveInfos_, ERROR); for (size_t i = 0; i < activeInfoCount; ++i) { SensorActiveInfo *curActiveInfo = sensorActiveInfos_ + i; diff --git a/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp b/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp index 2c94f505..1b9dc4eb 100644 --- a/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp +++ b/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp @@ -19,7 +19,7 @@ #include #include -void SensorDataCallbackImpl(SensorEvent *event) +void SensorDataCallbackImpl(const SensorEvent *event) { if (event == nullptr) { return; -- Gitee From a81c59c5088800db9c08bbb6f83814d71ca25ecf Mon Sep 17 00:00:00 2001 From: bailu1992 Date: Wed, 10 Jan 2024 10:48:32 +0800 Subject: [PATCH 2/3] =?UTF-8?q?sensor=20=E5=91=8A=E8=AD=A6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bailu1992 --- .../interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp b/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp index 1b9dc4eb..2c94f505 100644 --- a/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp +++ b/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp @@ -19,7 +19,7 @@ #include #include -void SensorDataCallbackImpl(const SensorEvent *event) +void SensorDataCallbackImpl(SensorEvent *event) { if (event == nullptr) { return; -- Gitee From 1eeadaae958c7bbcb085acbb8bb2a06da8756106 Mon Sep 17 00:00:00 2001 From: bailu1992 Date: Wed, 10 Jan 2024 18:44:25 +0800 Subject: [PATCH 3/3] =?UTF-8?q?sensor=20=E5=91=8A=E8=AD=A6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bailu1992 --- frameworks/native/src/sensor_agent_proxy.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/native/src/sensor_agent_proxy.cpp b/frameworks/native/src/sensor_agent_proxy.cpp index eb6f3fdd..14152488 100644 --- a/frameworks/native/src/sensor_agent_proxy.cpp +++ b/frameworks/native/src/sensor_agent_proxy.cpp @@ -275,7 +275,7 @@ int32_t SensorAgentProxy::ConvertSensorInfos() const SEN_HILOGE("The number of sensors exceeds the maximum value"); return ERROR; } - sensorInfos_ = static_cast(malloc(sizeof(SensorInfo) * count)); + sensorInfos_ = (SensorInfo *)malloc(sizeof(SensorInfo) * count); CHKPR(sensorInfos_, ERROR); for (size_t i = 0; i < count; ++i) { SensorInfo *sensorInfo = sensorInfos_ + i; @@ -382,7 +382,7 @@ int32_t SensorAgentProxy::GetSensorActiveInfos(int32_t pid, SEN_HILOGE("The number of active info exceeds the maximum value, count:%{public}zu", activeInfoCount); return ERROR; } - sensorActiveInfos_ = static_cast(malloc(sizeof(SensorActiveInfo) * activeInfoCount)); + sensorActiveInfos_ = (SensorActiveInfo *)malloc(sizeof(SensorActiveInfo) * activeInfoCount); CHKPR(sensorActiveInfos_, ERROR); for (size_t i = 0; i < activeInfoCount; ++i) { SensorActiveInfo *curActiveInfo = sensorActiveInfos_ + i; -- Gitee