World Clock: Bug fix. Possible try to access memory beyond the array. 25/90325/7
authorRadoslaw Czerski <r.czerski@samsung.com>
Thu, 6 Oct 2016 10:53:57 +0000 (12:53 +0200)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Tue, 11 Oct 2016 13:29:36 +0000 (06:29 -0700)
Fix: Iteration begins with 0.

Change-Id: Idec88eb9d793f113135151866cfc293a980f8df5
Signed-off-by: Radoslaw Czerski <r.czerski@samsung.com>
clock/src/Model/WorldClock.cpp

index 5fcec2a..6c6d1b2 100644 (file)
@@ -165,20 +165,18 @@ int WorldClock::GetCurrentTimezoneNo() const
 
 int WorldClock::GetTimezoneNo(const model::Timezone *timezone) const
 {
-       for (int i = timezone->gmt_offset / 60 + 11; i < time_zones_.size(); i++) {
-                       if (time_zones_.at(i).gmt_offset == timezone->gmt_offset) {
-                               return i;
-                       }
-               }
+       for (auto it = time_zones_.begin() ; it != time_zones_.end(); it++) {
+               if (it->gmt_offset == timezone->gmt_offset)
+                       return it - time_zones_.begin();
+       }
        return -1;
 }
 
 const Timezone *WorldClock::GetTimezoneByOffset(int offset) const
 {
-       for (int i = offset / 60 + 11; i < time_zones_.size(); i++) {
-               if (time_zones_.at(i).gmt_offset == offset) {
-                       return &time_zones_.at(i);
-               }
+       for (auto &it: time_zones_) {
+               if (it.gmt_offset == offset)
+                       return &(it);
        }
        return NULL;
 }