diff options
Diffstat (limited to 'Objects/bytearrayobject.c')
-rw-r--r-- | Objects/bytearrayobject.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 8aa2928d20..c4a25c0d9a 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -6,6 +6,7 @@ #include "bytes_methods.h" static PyByteArrayObject *nullbytes = NULL; +char _PyByteArray_empty_string[] = ""; void PyByteArray_Fini(void) @@ -74,7 +75,7 @@ bytes_buffer_getreadbuf(PyByteArrayObject *self, Py_ssize_t index, const void ** "accessing non-existent bytes segment"); return -1; } - *ptr = (void *)self->ob_bytes; + *ptr = (void *)PyByteArray_AS_STRING(self); return Py_SIZE(self); } @@ -86,7 +87,7 @@ bytes_buffer_getwritebuf(PyByteArrayObject *self, Py_ssize_t index, const void * "accessing non-existent bytes segment"); return -1; } - *ptr = (void *)self->ob_bytes; + *ptr = (void *)PyByteArray_AS_STRING(self); return Py_SIZE(self); } @@ -106,7 +107,7 @@ bytes_buffer_getcharbuf(PyByteArrayObject *self, Py_ssize_t index, const char ** "accessing non-existent bytes segment"); return -1; } - *ptr = self->ob_bytes; + *ptr = PyByteArray_AS_STRING(self); return Py_SIZE(self); } @@ -119,10 +120,7 @@ bytes_getbuffer(PyByteArrayObject *obj, Py_buffer *view, int flags) obj->ob_exports++; return 0; } - if (obj->ob_bytes == NULL) - ptr = ""; - else - ptr = obj->ob_bytes; + ptr = (void *) PyByteArray_AS_STRING(obj); ret = PyBuffer_FillInfo(view, (PyObject*)obj, ptr, Py_SIZE(obj), 0, flags); if (ret >= 0) { obj->ob_exports++; @@ -201,7 +199,7 @@ PyByteArray_FromStringAndSize(const char *bytes, Py_ssize_t size) Py_DECREF(new); return PyErr_NoMemory(); } - if (bytes != NULL) + if (bytes != NULL && size > 0) memcpy(new->ob_bytes, bytes, size); new->ob_bytes[size] = '\0'; /* Trailing null byte */ } |