Skip to content

Don't rely on undefined left shift behavior in assert in PyStackRef_TagInt #140868

@DinoV

Description

@DinoV

Bug report

Bug description:

This assert https://github.com/python/cpython/blob/main/Include/internal/pycore_stackref.h#L406 contains a left shift of a potentially negative value which is undefined behavior. The non-assert line does a uintptr_t cast to avoid the undefined behavior. Replicate that in the assert and then cast the final value back to intptr_t.

This can show up when running with various sanitizers enabled.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions