Commit 7700a5da authored by Guido van Rossum's avatar Guido van Rossum

Better error messages when raising ValueError for int literals. (The

previous version of this code would not show the offending input, even
though there was code that attempted this.)
parent dd77993b
...@@ -696,22 +696,17 @@ strop_atoi(self, args) ...@@ -696,22 +696,17 @@ strop_atoi(self, args)
while (*s && isspace(Py_CHARMASK(*s))) while (*s && isspace(Py_CHARMASK(*s)))
s++; s++;
if (s[0] == '\0') {
PyErr_SetString(PyExc_ValueError, "empty string for atoi()");
return NULL;
}
errno = 0; errno = 0;
if (base == 0 && s[0] == '0') if (base == 0 && s[0] == '0')
x = (long) PyOS_strtoul(s, &end, base); x = (long) PyOS_strtoul(s, &end, base);
else else
x = PyOS_strtol(s, &end, base); x = PyOS_strtol(s, &end, base);
if (end == s || !isxdigit(end[-1])) { if (end == s || !isxdigit(end[-1]))
PyErr_SetString(PyExc_ValueError, "no digits in int constant"); goto bad;
return NULL;
}
while (*end && isspace(Py_CHARMASK(*end))) while (*end && isspace(Py_CHARMASK(*end)))
end++; end++;
if (*end != '\0') { if (*end != '\0') {
bad:
sprintf(buffer, "invalid literal for atoi(): %.200s", s); sprintf(buffer, "invalid literal for atoi(): %.200s", s);
PyErr_SetString(PyExc_ValueError, buffer); PyErr_SetString(PyExc_ValueError, buffer);
return NULL; return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment