swig/swig-3.0.12-Fix-Coverity-issue-reported-for-setslice-pycontainer.patch

41 lines
1.6 KiB
Diff

From 5803e81d488e97623fe29b8629b977be01a8229e Mon Sep 17 00:00:00 2001
From: Mark Dufour <m.dufour@kopano.com>
Date: Mon, 6 Mar 2017 21:16:41 +0100
Subject: [PATCH] Fix Coverity issue reported for setslice (pycontainer.swg):
"CID 11151 (#3-1 of 3): Using invalid iterator (INVALIDATE_ITERATOR)18.
increment_iterator: Incrementing iterator it though it is already past
the end of its container."
Coverity does not understand 'replace_count', so warns that we may go
past self->end() (or self->rend() I guess).
---
Lib/python/pycontainer.swg | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg
index d40b0baa8..9aefb4fc7 100644
--- a/Lib/python/pycontainer.swg
+++ b/Lib/python/pycontainer.swg
@@ -351,7 +351,7 @@ namespace swig {
typename Sequence::const_iterator isit = is.begin();
typename Sequence::iterator it = self->begin();
std::advance(it,ii);
- for (size_t rc=0; rc<replacecount; ++rc) {
+ for (size_t rc=0; rc<replacecount && it != self->end(); ++rc) {
*it++ = *isit++;
for (Py_ssize_t c=0; c<(step-1) && it != self->end(); ++c)
it++;
@@ -367,7 +367,7 @@ namespace swig {
typename Sequence::const_iterator isit = is.begin();
typename Sequence::reverse_iterator it = self->rbegin();
std::advance(it,size-ii-1);
- for (size_t rc=0; rc<replacecount; ++rc) {
+ for (size_t rc=0; rc<replacecount && it != self->rend(); ++rc) {
*it++ = *isit++;
for (Py_ssize_t c=0; c<(-step-1) && it != self->rend(); ++c)
it++;
--
2.14.3