]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-140868: Don't rely on undefined left shift behavior in assert (#140869)
authorDino Viehland <dinoviehland@meta.com>
Sat, 1 Nov 2025 16:23:58 +0000 (12:23 -0400)
committerGitHub <noreply@github.com>
Sat, 1 Nov 2025 16:23:58 +0000 (12:23 -0400)
Don't rely on undefined left shift behavior in assert

Include/internal/pycore_stackref.h

index 94fcb1d8aee52b4353548c03be63ffa1e837a0c9..15a703a08204dadf98d145ef7b77b6141764bc7d 100644 (file)
@@ -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) };
 }