]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fixing #121965 -- containment in xrange objects.
authorMoshe Zadka <moshez@math.huji.ac.il>
Fri, 30 Mar 2001 16:49:07 +0000 (16:49 +0000)
committerMoshe Zadka <moshez@math.huji.ac.il>
Fri, 30 Mar 2001 16:49:07 +0000 (16:49 +0000)
Misc/NEWS
Objects/rangeobject.c

index 8061231a0bf9145d4b651973ec7e58844cfe33fc..a4ed067a57a0e59b7a5948187b8c2bf5fbc316dc 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -31,6 +31,8 @@ http://sourceforge.net/tracker/index.php?func=detail&aid=<id>&group_id=5470&atid
 - #119622:  compile errors due to redundant atof decls. Removed from
   Python/compile.c and Python/marshal.c
 
+- #121965 -- fixing containment in xrange() objects
+
 
 What's New in Python 2.0?
 =========================
index 5c794fc204f42a940ee30fe274e6fa3d8984a6df..b3ce0c8650a9dfe717cd619164daa34683f41962 100644 (file)
@@ -2,6 +2,8 @@
 /* Range object implementation */
 
 #include "Python.h"
+#include "structmember.h"
+#include <string.h>
 
 typedef struct {
        PyObject_HEAD
@@ -193,21 +195,29 @@ range_contains(rangeobject *r, PyObject *obj)
        if (num < 0 && PyErr_Occurred())
                return -1;
 
-       if (num < r->start || (num - r->start) % r->step)
-               return 0;
-       if (num > (r->start + (r->len * r->step)))
-               return 0;
+       if (r->step > 0) {
+               if ((num < r->start) || ((num - r->start) % r->step))
+                       return 0;
+               if (num >= (r->start + (r->len * r->step)))
+                       return 0;
+       }
+       else {
+               if ((num > r->start) || ((num - r->start) % r->step))
+                       return 0;
+               if (num <= (r->start + (r->len * r->step)))
+                       return 0;
+       }
        return 1;
 }
 
 static PySequenceMethods range_as_sequence = {
-       (inquiry)range_length, /*sq_length*/
+       (inquiry)range_length,  /*sq_length*/
        (binaryfunc)range_concat, /*sq_concat*/
        (intargfunc)range_repeat, /*sq_repeat*/
        (intargfunc)range_item, /*sq_item*/
        (intintargfunc)range_slice, /*sq_slice*/
-       0,              /*sq_ass_item*/
-       0,              /*sq_ass_slice*/
+       0,                      /*sq_ass_item*/
+       0,                      /*sq_ass_slice*/
        (objobjproc)range_contains, /*sq_contains*/
 };