Skip to content

gh-148390: fix undefined behavior of memoryview(...).cast("?")#148454

Open
picnixz wants to merge 2 commits intopython:mainfrom
picnixz:fix/ubsan/memoryview-148390
Open

gh-148390: fix undefined behavior of memoryview(...).cast("?")#148454
picnixz wants to merge 2 commits intopython:mainfrom
picnixz:fix/ubsan/memoryview-148390

Conversation

@picnixz
Copy link
Copy Markdown
Member

@picnixz picnixz commented Apr 12, 2026

Copy link
Copy Markdown
Member

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the UB is fixed, please remove it from the suppressions list:

# Objects/memoryobject.c:3032:15: runtime error: load of value 2, which is not a valid value for type 'bool'
bool:Objects/memoryobject.c

Copy link
Copy Markdown
Member

@skirpichev skirpichev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Though, maybe move macro closer to unpack_single() definition?

@picnixz
Copy link
Copy Markdown
Member Author

picnixz commented Apr 13, 2026

Though, maybe move macro closer to unpack_single() definition?

The problem is that it's being used in two places so... I preferred moving it where we had "helpers".

}

// Return 0 if PTR represents "false", and 1 otherwise.
#define UNPACK_TO_BOOL(PTR) (memcmp((PTR), &(_Bool){0}, sizeof(_Bool)) != 0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What version of C supports &(_Bool){0}? It was not supported prior to C99, but does C99 support this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants