summaryrefslogtreecommitdiff
path: root/Lib/python/pycontainer.swg
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2013-03-25 19:26:12 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2013-03-26 21:38:45 +0000
commit38b2b95c30662e81518bd8321bbbbed1ab7dd300 (patch)
tree4e8d9eb22da3c5c65691d87f5005cee5b9ece9fe /Lib/python/pycontainer.swg
parent7eda619741a31ed73df512085f7256694173e877 (diff)
downloadswig-38b2b95c30662e81518bd8321bbbbed1ab7dd300.tar.gz
Fix some invalid iterator usage in Python when deleting/inserting slices from/into containers
Diffstat (limited to 'Lib/python/pycontainer.swg')
-rw-r--r--Lib/python/pycontainer.swg12
1 files changed, 4 insertions, 8 deletions
diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg
index 81909ae02..d4386622e 100644
--- a/Lib/python/pycontainer.swg
+++ b/Lib/python/pycontainer.swg
@@ -339,7 +339,7 @@ namespace swig {
std::advance(it,ii);
for (size_t rc=0; rc<replacecount; ++rc) {
*it++ = *isit++;
- for (Py_ssize_t c=0; c<(step-1); ++c)
+ for (Py_ssize_t c=0; c<(step-1) && it != self->end(); ++c)
it++;
}
}
@@ -357,7 +357,7 @@ namespace swig {
std::advance(it,size-ii-1);
for (size_t rc=0; rc<replacecount; ++rc) {
*it++ = *isit++;
- for (Py_ssize_t c=0; c<(-step-1); ++c)
+ for (Py_ssize_t c=0; c<(-step-1) && it != self->rend(); ++c)
it++;
}
}
@@ -383,9 +383,7 @@ namespace swig {
size_t delcount = (jj - ii + step - 1) / step;
while (delcount) {
it = self->erase(it);
- if (it==self->end())
- break;
- for (Py_ssize_t c=0; c<(step-1); ++c)
+ for (Py_ssize_t c=0; c<(step-1) && it != self->end(); ++c)
it++;
delcount--;
}
@@ -399,9 +397,7 @@ namespace swig {
size_t delcount = (ii - jj - step - 1) / -step;
while (delcount) {
it = typename Sequence::reverse_iterator(self->erase((++it).base()));
- if (it==self->rend())
- break;
- for (Py_ssize_t c=0; c<(-step-1); ++c)
+ for (Py_ssize_t c=0; c<(-step-1) && it != self->rend(); ++c)
it++;
delcount--;
}