From 7ca573ef352ac1f28f7baa3b93e3c0d28495f190 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Salgado Date: Thu, 7 May 2026 20:06:53 +0100 Subject: [PATCH] gh-106693: Explicitly mark ob_sval as unsigned char to avoid UB (GH-106826) (cherry picked from commit fbba343622c9e4a38c8ef0f0b0e311164394d76a) Co-authored-by: Pablo Galindo Salgado Signed-off-by: Pablo Galindo --- Include/cpython/bytesobject.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Include/cpython/bytesobject.h b/Include/cpython/bytesobject.h index 41537210b748a1..3cd2bc489e364e 100644 --- a/Include/cpython/bytesobject.h +++ b/Include/cpython/bytesobject.h @@ -5,7 +5,7 @@ typedef struct { PyObject_VAR_HEAD Py_DEPRECATED(3.11) Py_hash_t ob_shash; - char ob_sval[1]; + unsigned char ob_sval[1]; /* Invariants: * ob_sval contains space for 'ob_size+1' elements. @@ -20,7 +20,7 @@ PyAPI_FUNC(int) _PyBytes_Resize(PyObject **, Py_ssize_t); #define _PyBytes_CAST(op) \ (assert(PyBytes_Check(op)), _Py_CAST(PyBytesObject*, op)) -static inline char* PyBytes_AS_STRING(PyObject *op) +static inline unsigned char* PyBytes_AS_STRING(PyObject *op) { return _PyBytes_CAST(op)->ob_sval; }