Index: Objects/longobject.c =================================================================== RCS file: /projects/cvsroot/python/dist/src/Objects/longobject.c,v retrieving revision 1.40 diff -c -r1.40 longobject.c *** longobject.c 1998/04/10 22:16:36 1.40 --- longobject.c 1998/07/25 12:42:02 *************** *** 175,182 **** PyLong_AsLong(vv) PyObject *vv; { register PyLongObject *v; ! long x, prev; int i, sign; if (vv == NULL || !PyLong_Check(vv)) { --- 175,183 ---- PyLong_AsLong(vv) PyObject *vv; { + /* This version by Tim Peters */ register PyLongObject *v; ! unsigned long x, prev; int i, sign; if (vv == NULL || !PyLong_Check(vv)) { *************** *** 194,206 **** while (--i >= 0) { prev = x; x = (x << SHIFT) + v->ob_digit[i]; ! if ((x >> SHIFT) != prev) { ! PyErr_SetString(PyExc_OverflowError, ! "long int too long to convert"); ! return -1; ! } } ! return x * sign; } /* Get a C long int from a long int object. --- 195,216 ---- while (--i >= 0) { prev = x; x = (x << SHIFT) + v->ob_digit[i]; ! if ((x >> SHIFT) != prev) ! goto overflow; } ! /* Haven't lost any bits, but if the sign bit is set we're in ! * trouble *unless* this is the min negative number. So, ! * trouble iff sign bit set && (positive || some bit set other ! * than the sign bit). ! */ ! if ((long)x < 0 && (sign > 0 || (x << 1) != 0)) ! goto overflow; ! return (long)x * sign; ! ! overflow: ! PyErr_SetString(PyExc_OverflowError, ! "long int too long to convert"); ! return -1; } /* Get a C long int from a long int object. *************** *** 443,448 **** --- 453,459 ---- int base; { int sign = 1; + char *start; PyLongObject *z; if ((base != 0 && base < 2) || base > 36) { *************** *** 471,476 **** --- 482,488 ---- if (base == 16 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) str += 2; z = _PyLong_New(0); + start = str; for ( ; z != NULL; ++str) { int k = -1; PyLongObject *temp; *************** *** 486,491 **** --- 498,510 ---- temp = muladd1(z, (digit)base, (digit)k); Py_DECREF(z); z = temp; + } + if (z == NULL) + return NULL; + if (str == start) { + PyErr_SetString(PyExc_ValueError, + "no digits in long int constant"); + return NULL; } if (sign < 0 && z != NULL && z->ob_size != 0) z->ob_size = -(z->ob_size);