CleverRaven/Cataclysm-DDA — pull request #8076 by BevapDin (2014-06-28 23:41:41+00:00)
Title: Fix loop condition, should check for end, not start

Fix some bugs reported here/there: http://smf.cataclysmdda.com/index.php?topic=7022.0

The the manual iterations using the index had one advantage: they were immune to changes of the underlying container:
```
std::vector
&items = i_at(...);
for(size_t i = 0; i < items.size(); i++) {
if(destroy_this_item(items[i])) {
for(size_t j = 0; j < items[i].contents.size(); j++) {
items.push_back(items[i].contents[j]);
// ^^ technically, this invalidates the items vector
// but items[i] is still valid as the vector size has
// only been increased, items[i].contents is still accessible,
// as is items[i].contents[j]
}
items.erase(item.begin() + i);
i--;
}
}
```
Is *not* equal to: (taken from some code in field.cpp)
```
std::vector
&items = i_at(...);
for(auto it = items.begin(); it != items.end(); ) {
if(destroy_this_item(*it)) {
for(auto j = it->contents.begin(); j != it->contents.end(); j++) {
items.push_back(*j);
// ^^ technically, this invalidates the items vector, thereby
// invalidating it, and therefor invalidating j,
// 'it->contents' might not be accessible at all
}
it = items.erase(it);
// ^^ technically, the previous push_back might have already invalidated
// the iterator it.
} else {it++;}
}
```