summaryrefslogtreecommitdiffstats
path: root/Objects/abstract.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-08-03 17:55:06 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-08-03 17:55:06 (GMT)
commitf6d0aeeadce3f1aea240b900da5e1fbb430257b2 (patch)
tree824b3108bcbfeaa699766ab333ec43eefdc52bc8 /Objects/abstract.c
parent1f35ae0a3c7dc2d7709f60e62cb4d0aa7aeae490 (diff)
downloadcpython-f6d0aeeadce3f1aea240b900da5e1fbb430257b2.zip
cpython-f6d0aeeadce3f1aea240b900da5e1fbb430257b2.tar.gz
cpython-f6d0aeeadce3f1aea240b900da5e1fbb430257b2.tar.bz2
Issue #16741: Fix an error reporting in int().
Diffstat (limited to 'Objects/abstract.c')
-rw-r--r--Objects/abstract.c29
1 files changed, 5 insertions, 24 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 7c24724..7f1808f 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -1240,25 +1240,6 @@ convert_integral_to_int(PyObject *integral, const char *error_format)
}
-/* Add a check for embedded NULL-bytes in the argument. */
-static PyObject *
-long_from_string(const char *s, Py_ssize_t len)
-{
- char *end;
- PyObject *x;
-
- x = PyLong_FromString((char*)s, &end, 10);
- if (x == NULL)
- return NULL;
- if (end != s + len) {
- PyErr_SetString(PyExc_ValueError,
- "null byte in argument for int()");
- Py_DECREF(x);
- return NULL;
- }
- return x;
-}
-
PyObject *
PyNumber_Long(PyObject *o)
{
@@ -1306,16 +1287,16 @@ PyNumber_Long(PyObject *o)
if (PyBytes_Check(o))
/* need to do extra error checking that PyLong_FromString()
- * doesn't do. In particular int('9.5') must raise an
- * exception, not truncate the float.
+ * doesn't do. In particular int('9\x005') must raise an
+ * exception, not truncate at the null.
*/
- return long_from_string(PyBytes_AS_STRING(o),
- PyBytes_GET_SIZE(o));
+ return _PyLong_FromBytes(PyBytes_AS_STRING(o),
+ PyBytes_GET_SIZE(o), 10);
if (PyUnicode_Check(o))
/* The above check is done in PyLong_FromUnicode(). */
return PyLong_FromUnicodeObject(o, 10);
if (!PyObject_AsCharBuffer(o, &buffer, &buffer_len))
- return long_from_string(buffer, buffer_len);
+ return _PyLong_FromBytes(buffer, buffer_len, 10);
return type_error("int() argument must be a string or a "
"number, not '%.200s'", o);