robertwb / issues-import-test

0 stars 0 forks source link

ForIn and ForFrom loops will run with large unsigned start, and negative signed stop. #1001

Open robertwb opened 9 years ago

robertwb commented 9 years ago

The following the loops will run even though they shouldn't:

cdef unsigned int k = ((<unsigned int>-1)>>1) + 1  # Very large number
cdef int i = -1

cdef unsigned int j
for j from k <= j < i by 2:
    print j

for j in range(k, i, 2):
    print j

This is because the start value is larger than INT_MAX and C will default to an unsigned comparison, where the -1 representation appears to be UINT_MAX.

Migrated from http://trac.cython.org/ticket/849