From 13471a790eb808b5973dbc6b6b9ed258ce35061a Mon Sep 17 00:00:00 2001 From: "zhaoyuan17@huawei.com" Date: Wed, 29 Sep 2021 14:03:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=88=A0=E9=99=A4exception?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhaoyuan17@huawei.com --- services/formmgr/BUILD.gn | 1 - services/formmgr/src/form_data_mgr.cpp | 10 +++------- services/formmgr/src/form_sys_event_receiver.cpp | 11 +++-------- services/formmgr/src/form_util.cpp | 16 +++++----------- 4 files changed, 11 insertions(+), 27 deletions(-) diff --git a/services/formmgr/BUILD.gn b/services/formmgr/BUILD.gn index 1ea0f12821..5808dd089f 100644 --- a/services/formmgr/BUILD.gn +++ b/services/formmgr/BUILD.gn @@ -22,7 +22,6 @@ config("formmgr_config") { # "//base/miscservices/time/interfaces/innerkits/include", ] - cflags_cc = [ "-fexceptions" ] } group("fms_target") { diff --git a/services/formmgr/src/form_data_mgr.cpp b/services/formmgr/src/form_data_mgr.cpp index 1f5a45f847..79313055ed 100644 --- a/services/formmgr/src/form_data_mgr.cpp +++ b/services/formmgr/src/form_data_mgr.cpp @@ -1106,13 +1106,9 @@ void FormDataMgr::ParseAtTimerConfig(FormRecord &record, const FormItemInfo &inf } int hour = -1; int min = -1; - try { - hour = std::stoi(temp[0]); - min = std::stoi(temp[1]); - } catch (const std::exception& e) { - APP_LOGE("%{public}s, failed to stoi.", __func__); - } - + hour = std::stoi(temp[0]); + min = std::stoi(temp[1]); + if (hour < Constants::MIN_TIME || hour > Constants::MAX_HOUR || min < Constants::MIN_TIME || min > Constants::MAX_MININUTE) { APP_LOGE("%{public}s, time is invalid", __func__); diff --git a/services/formmgr/src/form_sys_event_receiver.cpp b/services/formmgr/src/form_sys_event_receiver.cpp index 0fd6edcd7a..2f76527080 100644 --- a/services/formmgr/src/form_sys_event_receiver.cpp +++ b/services/formmgr/src/form_sys_event_receiver.cpp @@ -406,14 +406,9 @@ void FormSysEventReceiver::GetTimerCfg(const bool updateEnabled, } int hour = -1; int min = -1; - try { - hour = std::stoi(temp[0]); - min = std::stoi(temp[1]); - } catch (const std::exception& e) { - APP_LOGE("%{public}s, failed to stoi.", __func__); - return; - } - + hour = std::stoi(temp[0]); + min = std::stoi(temp[1]); + if (hour < Constants::MIN_TIME || hour > Constants::MAX_HOUR || min < Constants::MIN_TIME || min > Constants::MAX_MININUTE) { APP_LOGE("%{public}s, time is invalid", __func__); diff --git a/services/formmgr/src/form_util.cpp b/services/formmgr/src/form_util.cpp index d033818a1b..d3f08c5f02 100644 --- a/services/formmgr/src/form_util.cpp +++ b/services/formmgr/src/form_util.cpp @@ -175,17 +175,11 @@ long FormUtil::GetMillisecondFromTm(struct tm &tmAtTime) */ std::vector FormUtil::StringSplit(const std::string &in, const std::string &delim) { - std::vector vEmpty; - try { - std::regex reg { delim }; - return std::vector { - std::sregex_token_iterator(in.begin(), in.end(), reg, -1), - std::sregex_token_iterator() - }; - } catch (const std::exception& e) { - APP_LOGE("%{public}s, failed to split string.", __func__); - } - return vEmpty; + std::regex reg { delim }; + return std::vector { + std::sregex_token_iterator(in.begin(), in.end(), reg, -1), + std::sregex_token_iterator() + }; } } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file -- Gitee From 8542a145feab5749c60cca188d3de6d7282cc179 Mon Sep 17 00:00:00 2001 From: "zhaoyuan17@huawei.com" Date: Wed, 29 Sep 2021 15:14:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=A0=E9=99=A4exception-patch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhaoyuan17@huawei.com --- services/formmgr/src/form_data_mgr.cpp | 7 +++---- services/formmgr/src/form_sys_event_receiver.cpp | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/services/formmgr/src/form_data_mgr.cpp b/services/formmgr/src/form_data_mgr.cpp index 79313055ed..94b4e638b6 100644 --- a/services/formmgr/src/form_data_mgr.cpp +++ b/services/formmgr/src/form_data_mgr.cpp @@ -1089,7 +1089,7 @@ void FormDataMgr::ParseIntervalConfig(FormRecord &record, const int configDurati * @param record The form record. * @param info form item info. */ -void FormDataMgr::ParseAtTimerConfig(FormRecord &record, const FormItemInfo &info) const +void FormDataMgr::ParseAtTimerConfig(FormRecord &record, const FormItemInfo &info) const { record.isEnableUpdate = false; record.updateDuration = 0; @@ -1099,7 +1099,7 @@ void FormDataMgr::ParseAtTimerConfig(FormRecord &record, const FormItemInfo &inf return; } - std::vector temp = FormUtil::StringSplit(configAtTime, Constants::TIME_DELIMETER); + std::vector temp = FormUtil::StringSplit(configAtTime, Constants::TIME_DELIMETER); if (temp.size() != Constants::UPDATE_AT_CONFIG_COUNT) { APP_LOGE("%{public}s, invalid config", __func__); return; @@ -1108,8 +1108,7 @@ void FormDataMgr::ParseAtTimerConfig(FormRecord &record, const FormItemInfo &inf int min = -1; hour = std::stoi(temp[0]); min = std::stoi(temp[1]); - - if (hour < Constants::MIN_TIME || hour > Constants::MAX_HOUR || min < Constants::MIN_TIME || min > + if (hour < Constants::MIN_TIME || hour > Constants::MAX_HOUR || min < Constants::MIN_TIME || min > Constants::MAX_MININUTE) { APP_LOGE("%{public}s, time is invalid", __func__); return; diff --git a/services/formmgr/src/form_sys_event_receiver.cpp b/services/formmgr/src/form_sys_event_receiver.cpp index 2f76527080..c6f3502236 100644 --- a/services/formmgr/src/form_sys_event_receiver.cpp +++ b/services/formmgr/src/form_sys_event_receiver.cpp @@ -370,7 +370,7 @@ void FormSysEventReceiver::ReCreateForm(const int64_t formId) want.SetParam(Constants::RECREATE_FORM_KEY, true); FormProviderMgr::GetInstance().ConnectAmsForRefresh(formId, reCreateRecord, want, false); } -void FormSysEventReceiver::GetTimerCfg(const bool updateEnabled, +void FormSysEventReceiver::GetTimerCfg(const bool updateEnabled, const int updateDuration, const std::string &configUpdateAt, FormTimerCfg& cfg) { APP_LOGI("%{public}s start", __func__); @@ -399,7 +399,7 @@ void FormSysEventReceiver::GetTimerCfg(const bool updateEnabled, } APP_LOGI("%{public}s,update at timer updateAt:%{public}s", __func__, configUpdateAt.c_str()); - std::vector temp = FormUtil::StringSplit(configUpdateAt, Constants::TIME_DELIMETER); + std::vector temp = FormUtil::StringSplit(configUpdateAt, Constants::TIME_DELIMETER); if (temp.size() != Constants::UPDATE_AT_CONFIG_COUNT) { APP_LOGE("%{public}s, invalid config", __func__); return; @@ -408,8 +408,7 @@ void FormSysEventReceiver::GetTimerCfg(const bool updateEnabled, int min = -1; hour = std::stoi(temp[0]); min = std::stoi(temp[1]); - - if (hour < Constants::MIN_TIME || hour > Constants::MAX_HOUR || min < Constants::MIN_TIME || min > + if (hour < Constants::MIN_TIME || hour > Constants::MAX_HOUR || min < Constants::MIN_TIME || min > Constants::MAX_MININUTE) { APP_LOGE("%{public}s, time is invalid", __func__); return; -- Gitee