Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 76b11c2c002f1310019dddcaf6b8076f009eb234 1 parent ae6508e
@Montellese Montellese authored
Showing with 5 additions and 11 deletions.
  1. +5 −11 xbmc/utils/SortUtils.cpp
View
16 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)
Please sign in to comment.
Something went wrong with that request. Please try again.