While experimenting with a CodeSonar plugin we develop, we noticed a potential bug in file "cpython/Objects/sliceobject.c" line 116 function PySlice_GetIndices. if (r->start == Py_None) { *start = *step < 0 ? length-1 : 0; } else { if (!PyInt_Check(r->start) && !PyLong_Check(r->step)) return -1;//HERE *start = PyInt_AsSsize_t(r->start); if (*start < 0) *start += length; } Shouldn't start field of r be used in the second check (instead of step)? In a related potential issue, in line 123, shouldn't r->stop be checked in the second verification? Thanks, Petru Florin Mihancea
Is there a way to test this or trigger this code using Python syntax? `slice(start, stop, step).indices()` uses slice_indices in Objects/sliceobject.c . I checked the function docs https://docs.python.org/2.7/c-api/slice.html#c.PySlice_GetIndices and it states below > You probably do not want to use this function. If you want to use slice objects in versions of Python prior to 2.3, you would probably do well to incorporate the source of PySlice_GetIndicesEx(), suitably renamed, in the source of your extension. I couldn't see it's usage too anywhere and with Python 3 we have all integers are implemented as “long” integer objects of arbitrary size and can see only PyLong_Check at https://github.com/python/cpython/blob/master/Objects/sliceobject.c#L178 Thanks