From a869c7cc28af1d2c1cded764545093113b800c8b Mon Sep 17 00:00:00 2001 From: rcy-hw Date: Sat, 19 Mar 2022 11:54:20 +0800 Subject: [PATCH] fixed 2b0ef2c from https://gitee.com/renchunyang2008/notification_ans_standard/pulls/353 fix codex Signed-off-by: rcy-hw Change-Id: Ia9e33c489b3b4c68d5a81b7c3dd576f149d33a28 --- .../native/src/reminder_request_calendar.cpp | 22 +++++++++---------- .../ans/native/src/reminder_request_timer.cpp | 6 ++++- frameworks/ans/native/src/reminder_store.cpp | 6 ++--- .../kits/napi/ans/src/reminder/publish.cpp | 2 +- .../napi/ans/src/reminder/reminder_common.cpp | 2 +- services/ans/src/reminder_data_manager.cpp | 8 +++++-- services/ans/src/reminder_event_manager.cpp | 6 ++++- 7 files changed, 32 insertions(+), 20 deletions(-) diff --git a/frameworks/ans/native/src/reminder_request_calendar.cpp b/frameworks/ans/native/src/reminder_request_calendar.cpp index b2490eb64..8acb45fd1 100644 --- a/frameworks/ans/native/src/reminder_request_calendar.cpp +++ b/frameworks/ans/native/src/reminder_request_calendar.cpp @@ -66,7 +66,7 @@ ReminderRequestCalendar::ReminderRequestCalendar(const tm &dateTime, // 2. set the time information (used to transfer to proxy service) which is decided to trigger firstly. year_ = static_cast(GetActualTime(TimeTransferType::YEAR, dateTime_.tm_year)); month_ = static_cast(GetActualTime(TimeTransferType::MONTH, dateTime_.tm_mon)); - day_ = dateTime_.tm_mday; + day_ = static_cast(dateTime_.tm_mday); second_ = 0; SetTriggerTimeInMilli(nextTriggerTime); } @@ -117,7 +117,7 @@ uint8_t ReminderRequestCalendar::GetNextDay( struct tm setTime; setTime.tm_year = GetCTime(TimeTransferType::YEAR, settedYear); setTime.tm_mon = GetCTime(TimeTransferType::MONTH, settedMonth); - setTime.tm_mday = i; + setTime.tm_mday = static_cast(i); setTime.tm_hour = target.tm_hour; setTime.tm_min = target.tm_min; setTime.tm_sec = target.tm_sec; @@ -215,10 +215,10 @@ uint64_t ReminderRequestCalendar::GetTimeInstantMilli( struct tm tar; tar.tm_year = GetCTime(TimeTransferType::YEAR, year); tar.tm_mon = GetCTime(TimeTransferType::MONTH, month); - tar.tm_mday = day; - tar.tm_hour = hour; - tar.tm_min = minute; - tar.tm_sec = second; + tar.tm_mday = static_cast(day); + tar.tm_hour = static_cast(hour); + tar.tm_min = static_cast(minute); + tar.tm_sec = static_cast(second); tar.tm_isdst = -1; ANSR_LOGD("tar: %{public}d-%{public}d-%{public}d %{public}d:%{public}d:%{public}d", @@ -235,10 +235,10 @@ void ReminderRequestCalendar::InitDateTime() { dateTime_.tm_year = GetCTime(TimeTransferType::YEAR, year_); dateTime_.tm_mon = GetCTime(TimeTransferType::MONTH, month_); - dateTime_.tm_mday = day_; - dateTime_.tm_hour = hour_; - dateTime_.tm_min = minute_; - dateTime_.tm_sec = second_; + dateTime_.tm_mday = static_cast(day_); + dateTime_.tm_hour = static_cast(hour_); + dateTime_.tm_min = static_cast(minute_); + dateTime_.tm_sec = static_cast(second_); dateTime_.tm_isdst = -1; } @@ -450,7 +450,7 @@ bool ReminderRequestCalendar::Marshalling(Parcel &parcel) const ReminderRequestCalendar *ReminderRequestCalendar::Unmarshalling(Parcel &parcel) { ANSR_LOGD("New calendar"); - auto objptr = new ReminderRequestCalendar(); + auto objptr = new (std::nothrow) ReminderRequestCalendar(); if (objptr == nullptr) { ANS_LOGE("Failed to create reminder calendar due to no memory."); return objptr; diff --git a/frameworks/ans/native/src/reminder_request_timer.cpp b/frameworks/ans/native/src/reminder_request_timer.cpp index 7dea55361..8e108f5e5 100644 --- a/frameworks/ans/native/src/reminder_request_timer.cpp +++ b/frameworks/ans/native/src/reminder_request_timer.cpp @@ -96,8 +96,12 @@ void ReminderRequestTimer::UpdateTimeInfo(const std::string &description) whenToChangeSysTime_ = ReminderRequest::GetDurationSinceEpochInMilli(now); sptr timer = MiscServices::TimeServiceClient::GetInstance(); int64_t bootTime = timer->GetBootTimeMs(); + if (bootTime < 0) { + ANSR_LOGW("BootTime is illegal"); + return; + } SetTriggerTimeInMilli(whenToChangeSysTime_ + (countDownTimeInSeconds_ * MILLI_SECONDS - - (bootTime - firstRealTimeInMilliSeconds_))); + (static_cast(bootTime) - firstRealTimeInMilliSeconds_))); } bool ReminderRequestTimer::Marshalling(Parcel &parcel) const diff --git a/frameworks/ans/native/src/reminder_store.cpp b/frameworks/ans/native/src/reminder_store.cpp index 1b51a5a9f..7babdc29e 100644 --- a/frameworks/ans/native/src/reminder_store.cpp +++ b/frameworks/ans/native/src/reminder_store.cpp @@ -342,15 +342,15 @@ sptr ReminderStore::BuildReminder(const std::shared_ptr reminder = nullptr; switch (reminderType) { case (static_cast(ReminderRequest::ReminderType::TIMER)): { - reminder = new ReminderRequestTimer(reminderId); + reminder = new (std::nothrow) ReminderRequestTimer(reminderId); break; } case (static_cast(ReminderRequest::ReminderType::CALENDAR)): { - reminder = new ReminderRequestCalendar(reminderId); + reminder = new (std::nothrow) ReminderRequestCalendar(reminderId); break; } case (static_cast(ReminderRequest::ReminderType::ALARM)): { - reminder = new ReminderRequestAlarm(reminderId); + reminder = new (std::nothrow) ReminderRequestAlarm(reminderId); break; } default: { diff --git a/interfaces/kits/napi/ans/src/reminder/publish.cpp b/interfaces/kits/napi/ans/src/reminder/publish.cpp index e49b96786..24470d6c3 100644 --- a/interfaces/kits/napi/ans/src/reminder/publish.cpp +++ b/interfaces/kits/napi/ans/src/reminder/publish.cpp @@ -152,7 +152,7 @@ napi_value ParseGetValidParameter(const napi_env &env, const napi_callback_info size_t argc = GET_VALID_PARAM_LEN; napi_value argv[GET_VALID_PARAM_LEN] = {nullptr}; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); - if (argc < 0 || argc > GET_VALID_PARAM_LEN) { + if (argc > GET_VALID_PARAM_LEN) { ANSR_LOGW("Wrong number of arguments"); return nullptr; } diff --git a/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp b/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp index 5f4ada3ae..a3ebc189d 100644 --- a/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp +++ b/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp @@ -518,7 +518,7 @@ napi_value ReminderCommon::ParseInt32Array(const napi_env &env, const napi_value return nullptr; } napi_get_value_int32(env, repeatDayVal, &propertyDayVal); - if (propertyDayVal < 1 || propertyDayVal > maxLen) { + if (propertyDayVal < 1 || propertyDayVal > static_cast(maxLen)) { ANSR_LOGW("%{public}s's element must between [1, %{public}d].", propertyName, maxLen); return nullptr; } diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index b08745ff5..417848546 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -901,7 +901,11 @@ void ReminderDataManager::LoadReminderFromDb() reminderVector_ = existReminders; ANSR_LOGD("LoadReminderFromDb, reminder size=%{public}d", reminderVector_.size()); for (auto it = reminderVector_.begin(); it != reminderVector_.end(); ++it) { - sptr bundleOption = new NotificationBundleOption(); + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + if (bundleOption == nullptr) { + ANSR_LOGE("Failed to create bundleOption due to no memory."); + break; + } int32_t reminderId = (*it)->GetReminderId(); if (!(store_->GetBundleOption(reminderId, bundleOption))) { ANSR_LOGE("Get bundle option fail, reminderId=%{public}d", reminderId); @@ -914,7 +918,7 @@ void ReminderDataManager::LoadReminderFromDb() continue; } } - totalCount_ = reminderVector_.size(); + totalCount_ = static_cast(reminderVector_.size()); ReminderRequest::GLOBAL_ID = store_->GetMaxId() + 1; } diff --git a/services/ans/src/reminder_event_manager.cpp b/services/ans/src/reminder_event_manager.cpp index 747a9a788..54dbe2cf4 100644 --- a/services/ans/src/reminder_event_manager.cpp +++ b/services/ans/src/reminder_event_manager.cpp @@ -59,7 +59,11 @@ void ReminderEventManager::init(std::shared_ptr &reminderDa IPCSkeleton::SetCallingIdentity(identity); sptr statusChangeListener - = new SystemAbilityStatusChangeListener(reminderDataManager); + = new (std::nothrow) SystemAbilityStatusChangeListener(reminderDataManager); + if (statusChangeListener == nullptr) { + ANSR_LOGE("Failed to create statusChangeListener due to no memory."); + return; + } sptr samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgrProxy == nullptr) { ANSR_LOGD("samgrProxy is null"); -- Gitee