Permalink
Browse files

SortUtils: fix potential crash in limiting

The state of an iterator is unknown after executing std::vector::erase()
so we can't grab it up front and use it after a call to erase().
  • Loading branch information...
1 parent ae6508e commit 76b11c2c002f1310019dddcaf6b8076f009eb234 @Montellese Montellese committed Jul 5, 2012
Showing with 5 additions and 11 deletions.
  1. +5 −11 xbmc/utils/SortUtils.cpp
@@ -657,19 +657,13 @@ void SortUtils::Sort(SortBy sortBy, SortOrder sortOrder, SortAttribute attribute
}
}
- if (limitEnd > 0 || limitStart > 0)
+ if (limitStart > 0 && (size_t)limitStart < items.size())
{
- SortItems::iterator start = items.begin();
- SortItems::iterator end = items.end();
-
- if (limitStart > 0 && (size_t)limitStart < items.size())
- start += limitStart;
- if (limitEnd > 0 && (size_t)limitEnd < items.size())
- end = items.begin() + limitEnd;
-
- items.erase(items.begin(), start);
- items.erase(end, items.end());
+ items.erase(items.begin(), items.begin() + limitStart);
+ limitEnd -= limitStart;
}
+ if (limitEnd > 0 && (size_t)limitEnd < items.size())
+ items.erase(items.begin() + limitEnd, items.end());
}
void SortUtils::Sort(const SortDescription &sortDescription, SortItems& items)

0 comments on commit 76b11c2

Please sign in to comment.