diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-01-17 12:38:54 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-01-17 12:38:54 (GMT) |
commit | fc8d6f4b73c995b6de2e2b1058140192cf1f7e72 (patch) | |
tree | 497231809932ff9a24c549b6d103e02f73779a0b /Include | |
parent | 1119a649167f8057f75b8fd26fa6cd2c1fc59a83 (diff) | |
download | cpython-fc8d6f4b73c995b6de2e2b1058140192cf1f7e72.zip cpython-fc8d6f4b73c995b6de2e2b1058140192cf1f7e72.tar.gz cpython-fc8d6f4b73c995b6de2e2b1058140192cf1f7e72.tar.bz2 |
Merged revisions 77573 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77573 | antoine.pitrou | 2010-01-17 13:26:20 +0100 (dim., 17 janv. 2010) | 6 lines
Issue #7561: Operations on empty bytearrays (such as `int(bytearray())`)
could crash in many places because of the PyByteArray_AS_STRING() macro
returning NULL. The macro now returns a statically allocated empty
string instead.
........
Diffstat (limited to 'Include')
-rw-r--r-- | Include/bytearrayobject.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Include/bytearrayobject.h b/Include/bytearrayobject.h index 265b4bb..8702e5a 100644 --- a/Include/bytearrayobject.h +++ b/Include/bytearrayobject.h @@ -44,9 +44,13 @@ PyAPI_FUNC(char *) PyByteArray_AsString(PyObject *); PyAPI_FUNC(int) PyByteArray_Resize(PyObject *, Py_ssize_t); /* Macros, trading safety for speed */ -#define PyByteArray_AS_STRING(self) (assert(PyByteArray_Check(self)),((PyByteArrayObject *)(self))->ob_bytes) +#define PyByteArray_AS_STRING(self) \ + (assert(PyByteArray_Check(self)), \ + Py_SIZE(self) ? ((PyByteArrayObject *)(self))->ob_bytes : _PyByteArray_empty_string) #define PyByteArray_GET_SIZE(self) (assert(PyByteArray_Check(self)),Py_SIZE(self)) +extern char _PyByteArray_empty_string[]; + #ifdef __cplusplus } #endif |