Message363310
Using memcpy() to write a value different than 0 or 1 into a _Bool is clearly an undefined behavior. Example with clang UBSan.
bool.c:
---
#include <string.h>
#include <stdbool.h>
int main()
{
char ch = 42;
_Bool x;
memcpy(&x, &ch, 1);
return x == true;
}
---
$ clang -fsanitize=bool bool.c -o bool
$ ./bool
bool.c:9:12: runtime error: load of value 42, which is not a valid value for type '_Bool' |
|
Date |
User |
Action |
Args |
2020-03-03 22:25:10 | vstinner | set | recipients:
+ vstinner, gregory.p.smith, mark.dickinson, benjamin.peterson, petr.viktorin, meador.inge, cstratak, ammar2 |
2020-03-03 22:25:10 | vstinner | set | messageid: <1583274310.32.0.931106124378.issue39689@roundup.psfhosted.org> |
2020-03-03 22:25:10 | vstinner | link | issue39689 messages |
2020-03-03 22:25:10 | vstinner | create | |
|