gh-148390: fix undefined behavior of memoryview(...).cast("?")#148454
gh-148390: fix undefined behavior of memoryview(...).cast("?")#148454picnixz wants to merge 2 commits intopython:mainfrom
memoryview(...).cast("?")#148454Conversation
StanFromIreland
left a comment
There was a problem hiding this comment.
If the UB is fixed, please remove it from the suppressions list:
cpython/Tools/ubsan/suppressions.txt
Lines 12 to 13 in 3ab94d6
skirpichev
left a comment
There was a problem hiding this comment.
Looks good.
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) |
There was a problem hiding this comment.
What version of C supports &(_Bool){0}? It was not supported prior to C99, but does C99 support this?
There was a problem hiding this comment.
It's supported since C99: https://en.cppreference.com/w/c/language/compound_literal.html.
There was a problem hiding this comment.
Great. But it seems that the unnamed _Bool object has automatic storage duration. I.e. it is created on the stack. Would not it be more efficient to use constant static object initialized only once?
memoryview.cast("?")has undocumented undefined behavior #148390