chiark / gitweb /
mp: Forbid negative bit numbers in {set,clear,test}bit methods.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 29 Jan 2006 13:55:35 +0000 (13:55 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 4 Feb 2006 17:52:11 +0000 (17:52 +0000)
mp.c

diff --git a/mp.c b/mp.c
index 4b73223c4cf57beaf6e2b2978d82facef3ceab38..0c0dd862b7bc93156899fedda7b51c6cccdd737e 100644 (file)
--- a/mp.c
+++ b/mp.c
@@ -535,8 +535,8 @@ end:
 #define BITOP(pre, name, c)                                            \
   static PyObject *pre##meth_##name(PyObject *me, PyObject *arg)       \
   {                                                                    \
-    int i;                                                             \
-    if (!PyArg_ParseTuple(arg, "i:" #name, &i)) return (0);            \
+    unsigned long i;                                                   \
+    if (!PyArg_ParseTuple(arg, "O&:" #name, convulong, &i)) return (0);        \
     return (pre##_pywrap(mp_##name##c(MP_NEW, MP_X(me), i)));          \
   }
 BITOP(mp, setbit, 2c);
@@ -547,15 +547,15 @@ BITOP(gf, clearbit, );
 
 static PyObject *mpmeth_testbit(PyObject *me, PyObject *arg)
 {
-  int i;
-  if (!PyArg_ParseTuple(arg, "i:testbit", &i)) return (0);
+  unsigned long i;
+  if (!PyArg_ParseTuple(arg, "O&:testbit", convulong, &i)) return (0);
   return (getbool(mp_testbit2c(MP_X(me), i)));
 }
 
 static PyObject *gfmeth_testbit(PyObject *me, PyObject *arg)
 {
-  int i;
-  if (!PyArg_ParseTuple(arg, "i:testbit", &i)) return (0);
+  unsigned long i;
+  if (!PyArg_ParseTuple(arg, "O&:testbit", convulong, &i)) return (0);
   return (getbool(mp_testbit(MP_X(me), i)));
 }