From 9e10e96d42e0dc89607635339976bf76c3239733 Mon Sep 17 00:00:00 2001 From: ruan-shaofei Date: Thu, 1 Sep 2022 11:14:42 +0800 Subject: [PATCH] add nullptr protect Signed-off-by: ruan-shaofei --- .../locator/source/country_code_manager.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/services/location_locator/locator/source/country_code_manager.cpp b/services/location_locator/locator/source/country_code_manager.cpp index f46e6fffd..01c227629 100644 --- a/services/location_locator/locator/source/country_code_manager.cpp +++ b/services/location_locator/locator/source/country_code_manager.cpp @@ -121,6 +121,9 @@ std::string CountryCodeManager::GetCountryCodeByLastLocation() std::shared_ptr reportManager = DelayedSingleton::GetInstance(); if (reportManager) { auto lastLocation = reportManager->GetLastLocation(); + if (lastLocation == nullptr) { + return code; + } auto location = std::make_unique(*lastLocation); code = GetCountryCodeByLocation(location); lastCountryByLocation_->SetCountryCodeStr(code); @@ -262,14 +265,12 @@ bool CountryCodeManager::SubscribeLocaleConfigEvent() { auto eventCallback = [](const char *key, const char *value, void *context) { LBSLOGD(COUNTRY_CODE, "LOCALE_KEY changed"); - if (key && value && context) { - auto manager = DelayedSingleton::GetInstance(); - if (manager == nullptr) { - LBSLOGE(COUNTRY_CODE, "SubscribeLocaleConfigEvent CountryCodeManager is nullptr"); - return; - } - manager->GetIsoCountryCode(); + auto manager = DelayedSingleton::GetInstance(); + if (manager == nullptr) { + LBSLOGE(COUNTRY_CODE, "SubscribeLocaleConfigEvent CountryCodeManager is nullptr"); + return; } + manager->GetIsoCountryCode(); }; int ret = WatchParameter(LOCALE_KEY.c_str(), eventCallback, nullptr);