.bytes_characters = _Py_bytes_characters_INIT, \
#define _Py_bytes_characters_INIT { \
_PyBytes_CHAR_INIT(0), \
_PyBytes_CHAR_INIT(1), \
_PyBytes_CHAR_INIT(2), \
_PyBytes_CHAR_INIT(3), \
_PyBytes_CHAR_INIT(4), \
_PyBytes_CHAR_INIT(5), \
_PyBytes_CHAR_INIT(6), \
_PyBytes_CHAR_INIT(7), \
_PyBytes_CHAR_INIT(8), \
_PyBytes_CHAR_INIT(9), \
...
_PyBytes_CHAR_INIT(255), \
#define _PyBytes_CHAR_INIT(CH) \
{ \
_PyBytes_SIMPLE_INIT((CH), 1) \
}
#define _PyBytes_SIMPLE_INIT(CH, LEN) \
{ \
_PyVarObject_HEAD_INIT(&PyBytes_Type, (LEN)) \
.ob_shash = -1, \
.ob_sval = { (CH) }, \
}
in
bytes_charactersin https://github.com/python/cpython/blob/main/Include/internal/pycore_runtime_init.h we are doing this:where
with
but
cpython/Include/internal/pycore_global_objects.h
Lines 41 to 44 in e4b88c1
and
cpython/Include/cpython/bytesobject.h
Lines 5 to 15 in e4b88c1
I think this is UB because when we are basically assigning 255 to:
https://github.com/python/cpython/blob/e4b88c1e4ac129b36f99a534387d64f7b8cda8ef/Include/cpython/bytesobject.h#L8C10-L8C17
and that should be a
unsigned charbecause the range ofcharcan be 0 to 255 or -128 to 127 depending on the platform.Linked PRs