]> granicus.if.org Git - python/commitdiff
Add check in long-to-int conversion for at least one digit.
authorGuido van Rossum <guido@python.org>
Mon, 22 Jun 1998 03:54:46 +0000 (03:54 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 22 Jun 1998 03:54:46 +0000 (03:54 +0000)
Objects/longobject.c

index 9657c08f74f2ac56c6c567964592257f647d4b94..d638c64412a51b69476614160d6e9f7cdddc090e 100644 (file)
@@ -453,6 +453,7 @@ PyLong_FromString(str, pend, base)
        int base;
 {
        int sign = 1;
+       char *start;
        PyLongObject *z;
        
        if ((base != 0 && base < 2) || base > 36) {
@@ -481,6 +482,7 @@ PyLong_FromString(str, pend, base)
        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;
@@ -497,6 +499,11 @@ PyLong_FromString(str, pend, base)
                Py_DECREF(z);
                z = temp;
        }
+       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);
        if (pend)