mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Issue #24802: Merge null termination fixes from 3.4 into 3.5
This commit is contained in:
commit
61d6e4ae9d
8 changed files with 161 additions and 36 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue