From 537672d43ae28751b6334fa9755ef9c9cd7bde46 Mon Sep 17 00:00:00 2001 From: wlj Date: Fri, 8 Jul 2022 16:14:13 +0800 Subject: [PATCH] fix empty xml config bug Signed-off-by: wlj Change-Id: Ie0dbebf764ddbe5c46caf2762dc0120d54de4cc4 --- utils/include/window_helper.h | 6 ++++++ wmserver/src/window_manager_config.cpp | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/utils/include/window_helper.h b/utils/include/window_helper.h index ff3be69c..b831397d 100644 --- a/utils/include/window_helper.h +++ b/utils/include/window_helper.h @@ -277,6 +277,9 @@ public: static inline bool IsNumber(std::string str) { + if (str.size() == 0) { + return false; + } for (int32_t i = 0; i < static_cast(str.size()); i++) { if (str.at(i) < '0' || str.at(i) > '9') { return false; @@ -287,6 +290,9 @@ public: static inline bool IsFloatingNumber(std::string str) { + if (str.size() == 0) { + return false; + } for (int32_t i = 0; i < static_cast(str.size()); i++) { if ((str.at(i) < '0' || str.at(i) > '9') && (str.at(i) != '.' || std::count(str.begin(), str.end(), '.') > 1)) { diff --git a/wmserver/src/window_manager_config.cpp b/wmserver/src/window_manager_config.cpp index f217047d..cdc0d615 100644 --- a/wmserver/src/window_manager_config.cpp +++ b/wmserver/src/window_manager_config.cpp @@ -123,6 +123,10 @@ void WindowManagerConfig::ReadIntNumbersConfigInfo(const xmlNodePtr& currNode) std::vector numbersVec; std::string numbersStr = reinterpret_cast(context); + if (numbersStr.size() == 0) { + xmlFree(context); + return; + } auto numbers = WindowHelper::Split(numbersStr, " "); for (auto& num : numbers) { if (!WindowHelper::IsNumber(num)) { @@ -149,6 +153,10 @@ void WindowManagerConfig::ReadFloatNumbersConfigInfo(const xmlNodePtr& currNode) std::vector numbersVec; std::string numbersStr = reinterpret_cast(context); + if (numbersStr.size() == 0) { + xmlFree(context); + return; + } auto numbers = WindowHelper::Split(numbersStr, " "); for (auto& num : numbers) { if (!WindowHelper::IsFloatingNumber(num)) {