]> granicus.if.org Git - python/commitdiff
Better error messages when raising ValueError for int literals. (The
authorGuido van Rossum <guido@python.org>
Tue, 4 Aug 1998 15:04:52 +0000 (15:04 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 4 Aug 1998 15:04:52 +0000 (15:04 +0000)
previous version of this code would not show the offending input, even
though there was code that attempted this.)

Modules/stropmodule.c

index 73a35c9b5c83fc0cfbed55c598679f99ea48e139..34ac71ad658d1002377ffe871df1ef5f514a02c6 100644 (file)
@@ -696,22 +696,17 @@ strop_atoi(self, args)
 
        while (*s && isspace(Py_CHARMASK(*s)))
                s++;
-       if (s[0] == '\0') {
-               PyErr_SetString(PyExc_ValueError, "empty string for atoi()");
-               return NULL;
-       }
        errno = 0;
        if (base == 0 && s[0] == '0')
                x = (long) PyOS_strtoul(s, &end, base);
        else
                x = PyOS_strtol(s, &end, base);
-       if (end == s || !isxdigit(end[-1])) {
-               PyErr_SetString(PyExc_ValueError, "no digits in int constant");
-               return NULL;
-       }
+       if (end == s || !isxdigit(end[-1]))
+               goto bad;
        while (*end && isspace(Py_CHARMASK(*end)))
                end++;
        if (*end != '\0') {
+  bad:
                sprintf(buffer, "invalid literal for atoi(): %.200s", s);
                PyErr_SetString(PyExc_ValueError, buffer);
                return NULL;