From 6877d47dbc5ca95a0b76366d637e97805ca28472 Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Fri, 19 Dec 2014 11:56:52 +0000 Subject: [PATCH] (ItemView) Fix Klocwork reported issue [Problem] Reverse_iter is dereferenced before we check if it's valid. [Solution] Check if it's valid before we use it. Change-Id: I96bdd0c30d35faf8c9a31507925218ed4b372a23 --- .../controls/scrollable/item-view/item-view-impl.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp b/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp index 345a247..708d98f 100644 --- a/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp +++ b/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp @@ -724,16 +724,20 @@ void ItemView::InsertItem( Item newItem, float durationSeconds ) displacedActor = temp; iter->second.RemoveConstraints(); - mActiveLayout->ApplyConstraints(iter->second, iter->first, durationSeconds, mScrollPositionObject, Self() ); + mActiveLayout->ApplyConstraints( iter->second, iter->first, durationSeconds, mScrollPositionObject, Self() ); } // Create last item - ItemId lastId = mItemPool.rbegin()->first; - Item lastItem( lastId + 1, displacedActor ); - mItemPool.insert( lastItem ); + ItemPool::reverse_iterator lastIter = mItemPool.rbegin(); + if ( lastIter != mItemPool.rend() ) + { + ItemId lastId = lastIter->first; + Item lastItem( lastId + 1, displacedActor ); + mItemPool.insert( lastItem ); - lastItem.second.RemoveConstraints(); - mActiveLayout->ApplyConstraints(lastItem.second, lastItem.first, durationSeconds, mScrollPositionObject, Self() ); + lastItem.second.RemoveConstraints(); + mActiveLayout->ApplyConstraints( lastItem.second, lastItem.first, durationSeconds, mScrollPositionObject, Self() ); + } } CalculateDomainSize(Self().GetCurrentSize()); -- 2.7.4