diff options
author | Martin Panter <vadmium+py@gmail.com> | 2015-11-07 02:56:11 (GMT) |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2015-11-07 02:56:11 (GMT) |
commit | 61d6e4ae9db80e3f87104a03499ff89d3c275b22 (patch) | |
tree | 43160e9ff162635bb549ad31b7be875935cf0b86 /Objects/floatobject.c | |
parent | 9b566c324d2eb3ddbf00d5d7a78bea63cde4d15f (diff) | |
parent | eeb896c4116dd763efea45cb3c1b53257128f4e4 (diff) | |
download | cpython-61d6e4ae9db80e3f87104a03499ff89d3c275b22.zip cpython-61d6e4ae9db80e3f87104a03499ff89d3c275b22.tar.gz cpython-61d6e4ae9db80e3f87104a03499ff89d3c275b22.tar.bz2 |
Issue #24802: Merge null termination fixes from 3.4 into 3.5
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r-- | Objects/floatobject.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c index d681981..b8d6f2b 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -144,9 +144,24 @@ PyFloat_FromString(PyObject *v) return NULL; } } + else if (PyBytes_Check(v)) { + s = PyBytes_AS_STRING(v); + len = PyBytes_GET_SIZE(v); + } + else if (PyByteArray_Check(v)) { + s = PyByteArray_AS_STRING(v); + len = PyByteArray_GET_SIZE(v); + } else if (PyObject_GetBuffer(v, &view, PyBUF_SIMPLE) == 0) { s = (const char *)view.buf; len = view.len; + /* Copy to NUL-terminated buffer. */ + s_buffer = PyBytes_FromStringAndSize(s, len); + if (s_buffer == NULL) { + PyBuffer_Release(&view); + return NULL; + } + s = PyBytes_AS_STRING(s_buffer); } else { PyErr_Format(PyExc_TypeError, |