From 680092b8efaa2abf507b7c332b09409b79c9d48c Mon Sep 17 00:00:00 2001 From: hui1975 Date: Thu, 3 Nov 2022 19:23:54 +0800 Subject: [PATCH] =?UTF-8?q?sensor=E4=B8=ADread()=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=80=BC=E6=A0=A1=E9=AA=8C=E4=B8=93=E9=A1=B9=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hui1975 Change-Id: Ia6f8aa216f6978102cc655caf23af38bbea41bc2 --- .../sensor/src/sensor_service_proxy.cpp | 6 +++- utils/src/sensor.cpp | 28 ++++++++++--------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/frameworks/native/sensor/src/sensor_service_proxy.cpp b/frameworks/native/sensor/src/sensor_service_proxy.cpp index b0406b7a..76be0c8c 100755 --- a/frameworks/native/sensor/src/sensor_service_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_service_proxy.cpp @@ -177,7 +177,11 @@ std::vector SensorServiceProxy::GetSensorList() SEN_HILOGE("failed, ret:%{public}d", ret); return sensors; } - int32_t sensorCount = reply.ReadInt32(); + int32_t sensorCount; + if (!reply.ReadInt32(sensorCount)) { + SEN_HILOGE("Parcel read failed"); + return sensors; + } SEN_HILOGD("sensorCount:%{public}d", sensorCount); if (sensorCount > MAX_SENSOR_COUNT) { sensorCount = MAX_SENSOR_COUNT; diff --git a/utils/src/sensor.cpp b/utils/src/sensor.cpp index 3c0c2b7c..69d5a512 100644 --- a/utils/src/sensor.cpp +++ b/utils/src/sensor.cpp @@ -241,19 +241,21 @@ std::unique_ptr Sensor::Unmarshalling(Parcel &parcel) bool Sensor::ReadFromParcel(Parcel &parcel) { - sensorId_ = parcel.ReadUint32(); - sensorTypeId_ = parcel.ReadUint32(); - sensorName_ = parcel.ReadString(); - vendorName_ = parcel.ReadString(); - firmwareVersion_ = parcel.ReadString(); - hardwareVersion_ = parcel.ReadString(); - power_ = parcel.ReadFloat(); - maxRange_ = parcel.ReadFloat(); - resolution_ = parcel.ReadFloat(); - flags_ = parcel.ReadUint32(); - fifoMaxEventCount_ = parcel.ReadInt32(); - minSamplePeriodNs_ = parcel.ReadInt64(); - maxSamplePeriodNs_ = parcel.ReadInt64(); + if ((!parcel.ReadUint32(sensorId_)) || + (!parcel.ReadUint32(sensorTypeId_)) || + (!parcel.ReadString(sensorName_)) || + (!parcel.ReadString(vendorName_)) || + (!parcel.ReadString(firmwareVersion_)) || + (!parcel.ReadString(hardwareVersion_)) || + (!parcel.ReadFloat(power_)) || + (!parcel.ReadFloat(maxRange_)) || + (!parcel.ReadFloat(resolution_)) || + (!parcel.ReadUint32(flags_)) || + (!parcel.ReadInt32(fifoMaxEventCount_)) || + (!parcel.ReadInt64(minSamplePeriodNs_)) || + (!parcel.ReadInt64(maxSamplePeriodNs_))) { + return false; + } return true; } } // namespace Sensors -- Gitee