summaryrefslogtreecommitdiffstats
path: root/Include/bytearrayobject.h
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-01-17 12:26:20 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-01-17 12:26:20 (GMT)
commite80a6a4ead1da87d2a4149bfcbb95c1a3320dbc2 (patch)
tree8fd4b9d3e430610e4fea82bbc2974bca013d0c6a /Include/bytearrayobject.h
parentaee900338e76c9d0879bf9470bc3be7912b11817 (diff)
downloadcpython-e80a6a4ead1da87d2a4149bfcbb95c1a3320dbc2.zip
cpython-e80a6a4ead1da87d2a4149bfcbb95c1a3320dbc2.tar.gz
cpython-e80a6a4ead1da87d2a4149bfcbb95c1a3320dbc2.tar.bz2
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/bytearrayobject.h')
-rw-r--r--Include/bytearrayobject.h6
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