!1150 修复config配置项为空时crash的问题

Merge pull request !1150 from 王良江/br_wlj_fix_config
This commit is contained in:
openharmony_ci 2022-07-09 03:01:02 +00:00 committed by Gitee
commit 03414a9e62
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 14 additions and 0 deletions

View File

@ -278,6 +278,9 @@ public:
static inline bool IsNumber(std::string str)
{
if (str.size() == 0) {
return false;
}
for (int32_t i = 0; i < static_cast<int32_t>(str.size()); i++) {
if (str.at(i) < '0' || str.at(i) > '9') {
return false;
@ -288,6 +291,9 @@ public:
static inline bool IsFloatingNumber(std::string str)
{
if (str.size() == 0) {
return false;
}
for (int32_t i = 0; i < static_cast<int32_t>(str.size()); i++) {
if ((str.at(i) < '0' || str.at(i) > '9') &&
(str.at(i) != '.' || std::count(str.begin(), str.end(), '.') > 1)) {

View File

@ -123,6 +123,10 @@ void WindowManagerConfig::ReadIntNumbersConfigInfo(const xmlNodePtr& currNode)
std::vector<int> numbersVec;
std::string numbersStr = reinterpret_cast<const char*>(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<float> numbersVec;
std::string numbersStr = reinterpret_cast<const char*>(context);
if (numbersStr.size() == 0) {
xmlFree(context);
return;
}
auto numbers = WindowHelper::Split(numbersStr, " ");
for (auto& num : numbers) {
if (!WindowHelper::IsFloatingNumber(num)) {