diff options
author | Raymond Hettinger <python@rcn.com> | 2015-07-28 09:05:44 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2015-07-28 09:05:44 (GMT) |
commit | acd61b6e4092b316069a526930d8b3d43c1a14df (patch) | |
tree | 3e3abcb50bc23ef1b62788c70d99626f97def36d /Modules | |
parent | aaf6114b37df5b86d605e396ac0547e5cac492ae (diff) | |
download | cpython-acd61b6e4092b316069a526930d8b3d43c1a14df.zip cpython-acd61b6e4092b316069a526930d8b3d43c1a14df.tar.gz cpython-acd61b6e4092b316069a526930d8b3d43c1a14df.tar.bz2 |
Issue #24735: Fix invalid memory access in combinations_with_replacement()
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/itertoolsmodule.c | 12 |
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 */ |