summaryrefslogtreecommitdiff
path: root/src/components/policy/policy_regular/src/cache_manager.cc
diff options
context:
space:
mode:
authorIra Lytvynenko <ILytvynenko@luxoft.com>2017-04-12 20:33:44 +0300
committerIra Lytvynenko <ILytvynenko@luxoft.com>2017-05-11 12:51:16 +0300
commitffa1498f4c2eb414232efa2d7b6d7297de650f90 (patch)
treee356b896a015b47e98c350c360885e9673e89c95 /src/components/policy/policy_regular/src/cache_manager.cc
parent9e7a39af22c3587580cb2dcff44e6a9b6956d02c (diff)
downloadsdl_core-ffa1498f4c2eb414232efa2d7b6d7297de650f90.tar.gz
Fix UPDATE_NEEDED is sent in case of unconsented device
Add check that pt_exchanged_x_days_after_epoch is initialized
Diffstat (limited to 'src/components/policy/policy_regular/src/cache_manager.cc')
-rw-r--r--src/components/policy/policy_regular/src/cache_manager.cc14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc
index acdece0a70..e1a6544c23 100644
--- a/src/components/policy/policy_regular/src/cache_manager.cc
+++ b/src/components/policy/policy_regular/src/cache_manager.cc
@@ -539,16 +539,22 @@ bool CacheManager::SetCountersPassedForSuccessfulUpdate(
int CacheManager::DaysBeforeExchange(int current) {
LOG4CXX_AUTO_TRACE(logger_);
CACHE_MANAGER_CHECK(0);
+
+ const rpc::Optional<rpc::Integer<uint16_t, 0, 65535> >& days_after_epoch =
+ (pt_->policy_table.module_meta->pt_exchanged_x_days_after_epoch);
+
+ if (!days_after_epoch->is_initialized()) {
+ return -1;
+ }
+
const uint8_t limit = pt_->policy_table.module_config.exchange_after_x_days;
LOG4CXX_DEBUG(logger_,
"Exchange after: " << static_cast<int>(limit) << " days");
- const uint16_t days_after_epoch =
- (*pt_->policy_table.module_meta->pt_exchanged_x_days_after_epoch);
- LOG4CXX_DEBUG(logger_, "Epoch since last update: " << days_after_epoch);
+ LOG4CXX_DEBUG(logger_, "Epoch since last update: " << *days_after_epoch);
const uint16_t actual =
- std::max(static_cast<uint16_t>(current - days_after_epoch), uint16_t(0));
+ std::max(static_cast<uint16_t>(current - *days_after_epoch), uint16_t(0));
LOG4CXX_DEBUG(logger_, "The days since last update: " << actual);
return std::max(limit - actual, 0);