From 191d958939c63824d987ba09a807ec62b077a2a0 Mon Sep 17 00:00:00 2001 From: liqiao49 Date: Mon, 31 Jul 2023 20:42:47 +0800 Subject: [PATCH] fix cde warn Signed-off-by: liqiao49 --- common/include/input_hub.cpp | 6 +++--- .../inputinject/include/distributed_input_inject.h | 9 ++------- .../inputinject/src/distributed_input_node_manager.cpp | 6 +++--- services/state/src/dinput_state.cpp | 8 ++++---- utils/src/dinput_utils_tool.cpp | 2 +- 5 files changed, 13 insertions(+), 18 deletions(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index 41bbac7..afa54a5 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -449,7 +449,7 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string& devicePath) std::unique_lock my_lock(operationMutex_); DHLOGI("Opening device: %s", devicePath.c_str()); int fd = OpenInputDeviceFdByPath(devicePath); - if (fd == -1) { + if (fd == UN_INIT_FD_VALUE) { DHLOGE("The fd open failed, devicePath %s.", devicePath.c_str()); return ERR_DH_INPUT_HUB_OPEN_DEVICEPATH_FAIL; } @@ -476,7 +476,7 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string& devicePath) int32_t InputHub::QueryInputDeviceInfo(int fd, InputDevice& identifier) { - char buffer[256] = {0}; + char buffer[INPUT_EVENT_BUFFER_SIZE] = {0}; // Get device name. if (ioctl(fd, EVIOCGNAME(sizeof(buffer) - 1), &buffer) < 1) { DHLOGE( @@ -1279,7 +1279,7 @@ void InputHub::Device::Close() { if (fd >= 0) { ::close(fd); - fd = -1; + fd = UN_INIT_FD_VALUE; } } diff --git a/services/source/inputinject/include/distributed_input_inject.h b/services/source/inputinject/include/distributed_input_inject.h index 68d556e..bf28600 100644 --- a/services/source/inputinject/include/distributed_input_inject.h +++ b/services/source/inputinject/include/distributed_input_inject.h @@ -33,7 +33,6 @@ public: static DistributedInputInject &GetInstance(); int32_t RegisterDistributedHardware(const std::string& devId, const std::string& dhId, const std::string& parameters); - int32_t UnregisterDistributedHardware(const std::string& devId, const std::string& dhId); int32_t RegisterDistributedEvent(RawEvent* buffer, size_t bufferSize); int32_t StructTransJson(const InputDevice& pBuf, std::string& strDescriptor); @@ -45,22 +44,18 @@ public: const uint32_t sourcePhyWidth, const uint32_t sourcePhyHeight); int32_t RemoveVirtualTouchScreenNode(const std::string& dhId); int32_t GetVirtualTouchScreenFd(); - int32_t RegisterInputNodeListener(sptr listener); int32_t UnregisterInputNodeListener(sptr listener); - int32_t GetDhIdsByInputType(const std::string &devId, const uint32_t &inputTypes, std::vector &dhIds); + void NotifyNodeMgrScanVirNode(const std::string &dhId); void InputDeviceEventInject(const std::shared_ptr &rawEvent); + void SyncNodeOfflineInfo(const std::string &srcDevId, const std::string &sinkDevId, const std::string &sinkNodeId); void SyncNodeOnlineInfo(const std::string &srcDevId, const std::string &sinkDevId, const std::string &sinkNodeId, const std::string &sinkNodeDesc); - void SyncNodeOfflineInfo(const std::string &srcDevId, const std::string &sinkDevId, const std::string &sinkNodeId); - void GetVirtualKeyboardPathsByDhIds(const std::vector &dhIds, std::vector &shareDhidsPaths, std::vector &shareDhIds); - void NotifyNodeMgrScanVirNode(const std::string &dhId); - private: DistributedInputInject(); ~DistributedInputInject(); diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index 041d4de..2c4c7aa 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -193,7 +193,7 @@ void DistributedInputNodeManager::NotifyNodeMgrScanVirNode(const std::string &dh bool DistributedInputNodeManager::IsVirtualDev(int fd) { - char buffer[256] = {0}; + char buffer[INPUT_EVENT_BUFFER_SIZE] = {0}; std::string deviceName; if (ioctl(fd, EVIOCGNAME(sizeof(buffer) - 1), &buffer) < 1) { DHLOGE("Could not get device name for %s.", ConvertErrNo().c_str()); @@ -212,7 +212,7 @@ bool DistributedInputNodeManager::IsVirtualDev(int fd) bool DistributedInputNodeManager::GetDevDhIdByFd(int fd, std::string& dhId, std::string& physicalPath) { - char buffer[256] = {0}; + char buffer[INPUT_EVENT_BUFFER_SIZE] = {0}; if (ioctl(fd, EVIOCGPHYS(sizeof(buffer) - 1), &buffer) < 1) { DHLOGE("Could not get device physicalPath for %s.", ConvertErrNo().c_str()); return false; @@ -251,7 +251,7 @@ void DistributedInputNodeManager::OpenInputDevice(const std::string& devicePath, std::string curDhId; std::string physicalPath; int fd = OpenInputDeviceFdByPath(devicePath); - if (fd == -1) { + if (fd == UN_INIT_FD_VALUE) { DHLOGE("The fd open failed, devicePath %s.", devicePath.c_str()); return; } diff --git a/services/state/src/dinput_state.cpp b/services/state/src/dinput_state.cpp index 1ecdbfa..7dc5290 100644 --- a/services/state/src/dinput_state.cpp +++ b/services/state/src/dinput_state.cpp @@ -22,10 +22,10 @@ #include #include +#include "constants_dinput.h" #include "dinput_errcode.h" #include "dinput_log.h" #include "dinput_utils_tool.h" -#include "constants_dinput.h" #include "distributed_input_collector.h" #include "distributed_input_inject.h" #include "distributed_input_sink_transport.h" @@ -143,10 +143,10 @@ void DInputState::SpecEventInject(const int32_t &sessionId, std::vector keyboardNodeDhIds; DistributedInputCollector::GetInstance().GetShareKeyboardPathsByDhIds(dhids, keyboardNodePaths, keyboardNodeDhIds); DistributedInputInject::GetInstance().GetVirtualKeyboardPathsByDhIds(dhids, keyboardNodePaths, keyboardNodeDhIds); - ssize_t len = keyboardNodePaths.size(); - for (ssize_t i = 0; i < len; ++i) { + size_t len = keyboardNodePaths.size(); + for (size_t i = 0; i < len; ++i) { std::vector keyboardPressedKeys; - int fd = -1; + int fd = UN_INIT_FD_VALUE; CheckKeyboardState(keyboardNodeDhIds[i], keyboardNodePaths[i], keyboardPressedKeys, fd); for (auto &code : keyboardPressedKeys) { struct input_event event = { diff --git a/utils/src/dinput_utils_tool.cpp b/utils/src/dinput_utils_tool.cpp index bb6db41..659e93d 100644 --- a/utils/src/dinput_utils_tool.cpp +++ b/utils/src/dinput_utils_tool.cpp @@ -300,7 +300,7 @@ void CloseFd(int& fd) return; } close(fd); - fd = -1; + fd = UN_INIT_FD_VALUE; } int BitIsSet(const unsigned long *array, int bit) -- Gitee