From: Dino Viehland Date: Sat, 1 Nov 2025 16:23:58 +0000 (-0400) Subject: gh-140868: Don't rely on undefined left shift behavior in assert (#140869) X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b1554146c29182803d1df23d6367c07a429d21ba;p=thirdparty%2FPython%2Fcpython.git gh-140868: Don't rely on undefined left shift behavior in assert (#140869) Don't rely on undefined left shift behavior in assert --- diff --git a/Include/internal/pycore_stackref.h b/Include/internal/pycore_stackref.h index 94fcb1d8aee5..15a703a08204 100644 --- a/Include/internal/pycore_stackref.h +++ b/Include/internal/pycore_stackref.h @@ -403,7 +403,8 @@ PyStackRef_IsTaggedInt(_PyStackRef i) static inline _PyStackRef PyStackRef_TagInt(intptr_t i) { - assert(Py_ARITHMETIC_RIGHT_SHIFT(intptr_t, (i << Py_TAGGED_SHIFT), Py_TAGGED_SHIFT) == i); + assert(Py_ARITHMETIC_RIGHT_SHIFT(intptr_t, (intptr_t)(((uintptr_t)i) << Py_TAGGED_SHIFT), + Py_TAGGED_SHIFT) == i); return (_PyStackRef){ .bits = ((((uintptr_t)i) << Py_TAGGED_SHIFT) | Py_INT_TAG) }; }