diff options
author | Guido van Rossum <guido@python.org> | 1998-08-04 15:04:52 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-08-04 15:04:52 (GMT) |
commit | 923fece5bd7a8b4d52adabc3c96aa3b12de16220 (patch) | |
tree | 5ab7e71f327475b8b5bbbe7a126c9c3ebc62129c | |
parent | ac6a37ae55b0f165dee662d65976c2d3ab9d2325 (diff) | |
download | cpython-923fece5bd7a8b4d52adabc3c96aa3b12de16220.zip cpython-923fece5bd7a8b4d52adabc3c96aa3b12de16220.tar.gz cpython-923fece5bd7a8b4d52adabc3c96aa3b12de16220.tar.bz2 |
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.)
-rw-r--r-- | Modules/stropmodule.c | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/Modules/stropmodule.c b/Modules/stropmodule.c index 73a35c9..34ac71a 100644 --- a/Modules/stropmodule.c +++ b/Modules/stropmodule.c @@ -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; |