Add safety check to avoid crash in ASFlowLayoutController

This commit is contained in:
Li Tan
2015-01-08 11:49:31 -08:00
parent bacfcbd24d
commit 123cab757a

View File

@@ -153,7 +153,7 @@ static const std::pair<int, int> ASFindIndexForRange(const std::vector<std::vect
ASFlowLayoutDirection layoutDirection) {
std::pair<int, int> cur = pos, pre = pos;
if (range < 0.0 && cur.first >= 0 && cur.second >= 0) {
if (range < 0.0 && cur.first >= 0 && cur.first < nodes.size() && cur.second >= 0 && cur.second < nodes[cur.first].size()) {
// search backward
while (range < 0.0 && cur.first >= 0 && cur.second >= 0) {
pre = cur;
@@ -170,7 +170,7 @@ static const std::pair<int, int> ASFindIndexForRange(const std::vector<std::vect
}
} else {
// search forward
while (range > 0.0 && cur.first < nodes.size() && cur.second < nodes[cur.first].size()) {
while (range > 0.0 && cur.first >= 0 && cur.first < nodes.size() && cur.second >= 0 && cur.second < nodes[cur.first].size()) {
pre = cur;
CGSize size = nodes[cur.first][cur.second];
range -= layoutDirection == ASFlowLayoutDirectionHorizontal ? size.width : size.height;