summaryrefslogtreecommitdiffstats
path: root/Modules/itertoolsmodule.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2015-07-28 09:05:44 (GMT)
committerRaymond Hettinger <python@rcn.com>2015-07-28 09:05:44 (GMT)
commitacd61b6e4092b316069a526930d8b3d43c1a14df (patch)
tree3e3abcb50bc23ef1b62788c70d99626f97def36d /Modules/itertoolsmodule.c
parentaaf6114b37df5b86d605e396ac0547e5cac492ae (diff)
downloadcpython-acd61b6e4092b316069a526930d8b3d43c1a14df.zip
cpython-acd61b6e4092b316069a526930d8b3d43c1a14df.tar.gz
cpython-acd61b6e4092b316069a526930d8b3d43c1a14df.tar.bz2
Issue #24735: Fix invalid memory access in combinations_with_replacement()
Diffstat (limited to 'Modules/itertoolsmodule.c')
-rw-r--r--Modules/itertoolsmodule.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 6634a17..f5fa3fb 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -2787,11 +2787,13 @@ cwr_next(cwrobject *co)
if (result == NULL)
goto empty;
co->result = result;
- elem = PyTuple_GET_ITEM(pool, 0);
- for (i=0; i<r ; i++) {
- assert(indices[i] == 0);
- Py_INCREF(elem);
- PyTuple_SET_ITEM(result, i, elem);
+ if (n > 0) {
+ elem = PyTuple_GET_ITEM(pool, 0);
+ for (i=0; i<r ; i++) {
+ assert(indices[i] == 0);
+ Py_INCREF(elem);
+ PyTuple_SET_ITEM(result, i, elem);
+ }
}
} else {
/* Copy the previous result tuple or re-use it if available */