STINNER Victor <vstin...@python.org> added the comment:

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'

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39689>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to