diff options
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 0291b24..ac31e2f 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 */ |