diff options
| author | Serhiy Storchaka <storchaka@gmail.com> | 2013-08-03 18:14:05 (GMT) |
|---|---|---|
| committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-08-03 18:14:05 (GMT) |
| commit | 579ddc2fd4fd618b72d8202d79d75d22e7e0b60a (patch) | |
| tree | b6ac773514cfbef73d62130a0d3810626fbc38e7 /Objects/abstract.c | |
| parent | e633bed44a6354dd190c7e97e28c12dead787315 (diff) | |
| parent | f6d0aeeadce3f1aea240b900da5e1fbb430257b2 (diff) | |
| download | cpython-579ddc2fd4fd618b72d8202d79d75d22e7e0b60a.zip cpython-579ddc2fd4fd618b72d8202d79d75d22e7e0b60a.tar.gz cpython-579ddc2fd4fd618b72d8202d79d75d22e7e0b60a.tar.bz2 | |
Issue #16741: Fix an error reporting in int().
Diffstat (limited to 'Objects/abstract.c')
| -rw-r--r-- | Objects/abstract.c | 29 |
1 files changed, 5 insertions, 24 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c index 6c8c561..5f11c3d 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -1261,25 +1261,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) { @@ -1327,16 +1308,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); |
