From 0178899fe04158fab42e8d176d9f0ef8e78969cd Mon Sep 17 00:00:00 2001 From: wuzhihuitmac Date: Tue, 19 Dec 2023 03:21:30 +0000 Subject: [PATCH] Add null judgment Signed-off-by: wuzhihuitmac Change-Id: I44d3a1d6505a1aada51685339d14d181a2185458 --- services/include/sensor_manager.h | 4 ++-- services/src/sensor_data_processer.cpp | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/services/include/sensor_manager.h b/services/include/sensor_manager.h index c7773640..c5e8d031 100644 --- a/services/include/sensor_manager.h +++ b/services/include/sensor_manager.h @@ -53,8 +53,8 @@ private: #ifdef HDF_DRIVERS_INTERFACE_SENSOR SensorHdiConnection &sensorHdiConnection_ = SensorHdiConnection::GetInstance(); std::thread dataThread_; - sptr sensorDataProcesser_; - sptr reportDataCallback_; + sptr sensorDataProcesser_ = nullptr; + sptr reportDataCallback_ = nullptr; #endif // HDF_DRIVERS_INTERFACE_SENSOR ClientInfo &clientInfo_ = ClientInfo::GetInstance(); std::unordered_map sensorMap_; diff --git a/services/src/sensor_data_processer.cpp b/services/src/sensor_data_processer.cpp index 8c1b010f..47e83bb9 100644 --- a/services/src/sensor_data_processer.cpp +++ b/services/src/sensor_data_processer.cpp @@ -295,6 +295,10 @@ int32_t SensorDataProcesser::DataThread(sptr dataProcesser, CALL_LOG_ENTER; prctl(PR_SET_NAME, SENSOR_REPORT_THREAD_NAME.c_str()); do { + if (dataProcesser == nullptr || dataCallback == nullptr) { + SEN_HILOGE("dataProcesser or dataCallback is nullptr"); + return INVALID_POINTER; + } if (dataProcesser->ProcessEvents(dataCallback) == INVALID_POINTER) { SEN_HILOGE("Callback cannot be null"); return INVALID_POINTER; -- Gitee